Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): upgrade to faker v8 #1431

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ function generator (faker, options) {
// 如果没有返回主题,则使用命令行参数中的主题。
// 主题格式:'mqttx/simulate/myScenario/' + clientId,
message: JSON.stringify({
temp: faker.datatype.number({ min: 20, max: 80 }), // 在 20 到 80 之间生成随机温度。
hum: faker.datatype.number({ min: 40, max: 90 }), // 在 40 到 90 之间生成随机湿度。
temp: faker.number.int({ min: 20, max: 80 }), // 在 20 到 80 之间生成随机温度。
hum: faker.number.int({ min: 40, max: 90 }), // 在 40 到 90 之间生成随机湿度。
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"split2": "^4.1.0"
},
"devDependencies": {
"@faker-js/faker": "^7.6.0",
"@faker-js/faker": "^8.1.0",
"@types/concat-stream": "^2.0.0",
"@types/debug": "^4.1.12",
"@types/js-yaml": "^4.0.5",
Expand Down
2 changes: 1 addition & 1 deletion cli/src/scenarios/IEM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Faker } from '@faker-js/faker'
const calculateEnergyConsumption = (faker: Faker, maxPower: number) => {
const ratedPower = maxPower * 1000
const minInstantPower = ratedPower * 0.6
const instantPower = faker.datatype.number({ min: minInstantPower, max: ratedPower, precision: 0.001 })
const instantPower = faker.number.float({ min: minInstantPower, max: ratedPower, precision: 0.001 })
const energy = instantPower / 3600
return new Number(energy.toFixed(2))
}
Expand Down
14 changes: 7 additions & 7 deletions cli/src/scenarios/smart_home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ const generateRoomData = (faker: Faker, roomType: string): RoomData | KitchenDat

const baseData: RoomData = {
room_type: roomType,
temperature: faker.datatype.number({ min: 18, max: 26 }),
humidity: faker.datatype.number({ min: 30, max: 50 }),
temperature: faker.number.int({ min: 18, max: 26 }),
humidity: faker.number.int({ min: 30, max: 50 }),
lights_on: isDaytime ? faker.datatype.boolean() : !isSleepingHours,
window_open: isDaytime ? faker.datatype.boolean() : false,
}

if (isKitchen) {
const kitchenData: KitchenData = {
...baseData,
fridge_temperature: faker.datatype.number({ min: 2, max: 8 }),
fridge_temperature: faker.number.int({ min: 2, max: 8 }),
oven_on: faker.datatype.boolean(),
}
return kitchenData
Expand All @@ -53,7 +53,7 @@ const generateRoomData = (faker: Faker, roomType: string): RoomData | KitchenDat
const bathroomData: BathroomData = {
...baseData,
water_tap_running: faker.datatype.boolean(),
bath_water_level: faker.datatype.number({ min: 0, max: 100 }),
bath_water_level: faker.number.int({ min: 0, max: 100 }),
}
return bathroomData
}
Expand All @@ -73,9 +73,9 @@ const generator = (faker: Faker, options: SimulatePubOptions) => {
const { clientId } = options
if (!dataCache[clientId]) {
dataCache[clientId] = {
home_id: faker.datatype.uuid(),
owner_name: faker.name.fullName(),
address: faker.address.streetAddress(),
home_id: faker.string.uuid(),
owner_name: faker.person.fullName(),
address: faker.location.streetAddress(),
}
}

Expand Down
58 changes: 29 additions & 29 deletions cli/src/scenarios/tesla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const generator = (faker: Faker, options: SimulatePubOptions) => {
if (!dataCache[clientId]) {
dataCache[clientId] = {
car_id: faker.vehicle.vin(),
display_name: faker.name.firstName() + "'s Tesla",
display_name: faker.person.firstName() + "'s Tesla",
model: faker.helpers.arrayElement(['S', '3', 'X', 'Y']),
trim_badging: faker.lorem.word(),
exterior_color: faker.color.human(),
wheel_type: faker.lorem.word(),
spoiler_type: faker.lorem.word(),
geofence: faker.address.city(),
geofence: faker.location.city(),
}
}

Expand All @@ -26,13 +26,13 @@ const generator = (faker: Faker, options: SimulatePubOptions) => {
version: faker.system.semver(),
update_available: faker.datatype.boolean(),
update_version: faker.system.semver(),
latitude: faker.address.latitude(),
longitude: faker.address.longitude(),
latitude: faker.location.latitude(),
longitude: faker.location.longitude(),
shift_state: faker.helpers.arrayElement(['D', 'N', 'R', 'P']),
power: faker.datatype.number({ min: -10000, max: 10000 }),
speed: faker.datatype.number({ min: 0, max: 200 }),
heading: faker.datatype.number({ min: 0, max: 359 }),
elevation: faker.datatype.number({ min: -100, max: 5000 }),
power: faker.number.int({ min: -10000, max: 10000 }),
speed: faker.number.int({ min: 0, max: 200 }),
heading: faker.number.int({ min: 0, max: 359 }),
elevation: faker.number.int({ min: -100, max: 5000 }),
locked: faker.datatype.boolean(),
sentry_mode: faker.datatype.boolean(),
windows_open: faker.datatype.boolean(),
Expand All @@ -41,30 +41,30 @@ const generator = (faker: Faker, options: SimulatePubOptions) => {
frunk_open: faker.datatype.boolean(),
is_user_present: faker.datatype.boolean(),
is_climate_on: faker.datatype.boolean(),
inside_temp: faker.datatype.number({ min: -20, max: 50, precision: 0.1 }),
outside_temp: faker.datatype.number({ min: -20, max: 50, precision: 0.1 }),
inside_temp: faker.number.float({ min: -20, max: 50, precision: 0.1 }),
outside_temp: faker.number.float({ min: -20, max: 50, precision: 0.1 }),
is_preconditioning: faker.datatype.boolean(),
odometer: faker.datatype.number({ min: 0, max: 1000000 }),
est_battery_range_km: faker.datatype.number({ min: 0, max: 1000, precision: 0.1 }),
rated_battery_range_km: faker.datatype.number({ min: 0, max: 1000, precision: 0.1 }),
ideal_battery_range_km: faker.datatype.number({ min: 0, max: 1000, precision: 0.1 }),
battery_level: faker.datatype.number({ min: 0, max: 100 }),
usable_battery_level: faker.datatype.number({ min: 0, max: 100 }),
odometer: faker.number.int({ min: 0, max: 1000000 }),
est_battery_range_km: faker.number.float({ min: 0, max: 1000, precision: 0.1 }),
rated_battery_range_km: faker.number.float({ min: 0, max: 1000, precision: 0.1 }),
ideal_battery_range_km: faker.number.float({ min: 0, max: 1000, precision: 0.1 }),
battery_level: faker.number.int({ min: 0, max: 100 }),
usable_battery_level: faker.number.int({ min: 0, max: 100 }),
plugged_in: faker.datatype.boolean(),
charge_energy_added: faker.datatype.number({ min: 0, max: 100, precision: 0.01 }),
charge_limit_soc: faker.datatype.number({ min: 0, max: 100 }),
charge_energy_added: faker.number.float({ min: 0, max: 100, precision: 0.01 }),
charge_limit_soc: faker.number.int({ min: 0, max: 100 }),
charge_port_door_open: faker.datatype.boolean(),
charger_actual_current: faker.datatype.number({ min: 0, max: 100, precision: 0.01 }),
charger_power: faker.datatype.number({ min: 1, max: 100 }),
charger_voltage: faker.datatype.number({ min: 220, max: 240 }),
charge_current_request: faker.datatype.number({ min: 10, max: 50 }),
charge_current_request_max: faker.datatype.number({ min: 10, max: 50 }),
scheduled_charging_start_time: faker.date.future(7, new Date()).toISOString(),
time_to_full_charge: faker.datatype.number({ min: 0.5, max: 10, precision: 0.01 }),
tpms_pressure_fl: faker.datatype.number({ min: 2.0, max: 3.5, precision: 0.1 }),
tpms_pressure_fr: faker.datatype.number({ min: 2.0, max: 3.5, precision: 0.1 }),
tpms_pressure_rl: faker.datatype.number({ min: 2.0, max: 3.5, precision: 0.1 }),
tpms_pressure_rr: faker.datatype.number({ min: 2.0, max: 3.5, precision: 0.1 }),
charger_actual_current: faker.number.float({ min: 0, max: 100, precision: 0.01 }),
charger_power: faker.number.int({ min: 1, max: 100 }),
charger_voltage: faker.number.int({ min: 220, max: 240 }),
charge_current_request: faker.number.int({ min: 10, max: 50 }),
charge_current_request_max: faker.number.int({ min: 10, max: 50 }),
scheduled_charging_start_time: faker.date.future({ years: 7, refDate: new Date() }).toISOString(),
time_to_full_charge: faker.number.float({ min: 0.5, max: 10, precision: 0.01 }),
tpms_pressure_fl: faker.number.float({ min: 2.0, max: 3.5, precision: 0.1 }),
tpms_pressure_fr: faker.number.float({ min: 2.0, max: 3.5, precision: 0.1 }),
tpms_pressure_rl: faker.number.float({ min: 2.0, max: 3.5, precision: 0.1 }),
tpms_pressure_rr: faker.number.float({ min: 2.0, max: 3.5, precision: 0.1 }),
timestamp: Date.now(),
}
return {
Expand Down
66 changes: 33 additions & 33 deletions cli/src/scenarios/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const generator = (faker: Faker, options: SimulatePubOptions) => {
const { clientId } = options
if (!dataCache[clientId]) {
dataCache[clientId] = {
station_id: faker.datatype.uuid(),
city: faker.address.city(),
region: faker.address.state(),
latitude: faker.address.latitude(),
longitude: faker.address.longitude(),
station_id: faker.string.uuid(),
city: faker.location.city(),
region: faker.location.state(),
latitude: faker.location.latitude(),
longitude: faker.location.longitude(),
}
}

Expand All @@ -44,40 +44,40 @@ const generator = (faker: Faker, options: SimulatePubOptions) => {
current: {
last_updated_epoch: Date.now(),
last_updated: new Date().toLocaleString(),
temp_c: faker.datatype.number({ min: tempMin, max: tempMax, precision: 0.1 }),
temp_f: faker.datatype.number({ min: tempMin * 1.8 + 32, max: tempMax * 1.8 + 32, precision: 0.1 }),
temp_c: faker.number.float({ min: tempMin, max: tempMax, precision: 0.1 }),
temp_f: faker.number.float({ min: tempMin * 1.8 + 32, max: tempMax * 1.8 + 32, precision: 0.1 }),
is_day: isDay,
condition: {
text: condition,
icon: faker.image.imageUrl(),
code: faker.datatype.number({ min: 1000, max: 2000 }),
icon: faker.image.url(),
code: faker.number.int({ min: 1000, max: 2000 }),
},
wind_mph: faker.datatype.number({ min: 0, max: 100 }),
wind_kph: faker.datatype.number({ min: 0, max: 161 }),
wind_degree: faker.datatype.number({ min: 0, max: 360 }),
wind_mph: faker.number.int({ min: 0, max: 100 }),
wind_kph: faker.number.int({ min: 0, max: 161 }),
wind_degree: faker.number.int({ min: 0, max: 360 }),
wind_dir: faker.helpers.arrayElement(['N', 'S', 'E', 'W']),
pressure_mb: faker.datatype.number({ min: 980, max: 1040 }),
pressure_in: faker.datatype.number({ min: 28.9, max: 30.7, precision: 0.1 }),
precip_mm: season === 'Summer' ? faker.datatype.number({ min: 0, max: 50, precision: 0.1 }) : 0,
precip_in: season === 'Summer' ? faker.datatype.number({ min: 0, max: 1.97, precision: 0.01 }) : 0,
humidity: faker.datatype.number({ min: 0, max: 100 }),
cloud: isDay ? faker.datatype.number({ min: 0, max: 50 }) : faker.datatype.number({ min: 50, max: 100 }),
feelslike_c: faker.datatype.number({ min: tempMin, max: tempMax, precision: 0.1 }),
feelslike_f: faker.datatype.number({ min: tempMin * 1.8 + 32, max: tempMax * 1.8 + 32, precision: 0.1 }),
vis_km: isDay ? faker.datatype.number({ min: 0, max: 100 }) : faker.datatype.number({ min: 0, max: 50 }),
vis_miles: isDay ? faker.datatype.number({ min: 0, max: 62 }) : faker.datatype.number({ min: 0, max: 31 }),
uv: isDay ? faker.datatype.number({ min: 0, max: 10 }) : 0,
gust_mph: faker.datatype.number({ min: 0, max: 100 }),
gust_kph: faker.datatype.number({ min: 0, max: 161 }),
pressure_mb: faker.number.int({ min: 980, max: 1040 }),
pressure_in: faker.number.float({ min: 28.9, max: 30.7, precision: 0.1 }),
precip_mm: season === 'Summer' ? faker.number.float({ min: 0, max: 50, precision: 0.1 }) : 0,
precip_in: season === 'Summer' ? faker.number.float({ min: 0, max: 1.97, precision: 0.01 }) : 0,
humidity: faker.number.int({ min: 0, max: 100 }),
cloud: isDay ? faker.number.float({ min: 0, max: 50 }) : faker.number.float({ min: 50, max: 100 }),
feelslike_c: faker.number.float({ min: tempMin, max: tempMax, precision: 0.1 }),
feelslike_f: faker.number.float({ min: tempMin * 1.8 + 32, max: tempMax * 1.8 + 32, precision: 0.1 }),
vis_km: isDay ? faker.number.float({ min: 0, max: 100 }) : faker.number.float({ min: 0, max: 50 }),
vis_miles: isDay ? faker.number.float({ min: 0, max: 62 }) : faker.number.float({ min: 0, max: 31 }),
uv: isDay ? faker.number.int({ min: 0, max: 10 }) : 0,
gust_mph: faker.number.int({ min: 0, max: 100 }),
gust_kph: faker.number.int({ min: 0, max: 161 }),
air_quality: {
co: faker.datatype.number({ min: 0, max: 500 }),
no2: faker.datatype.number({ min: 0, max: 1, precision: 0.01 }),
o3: faker.datatype.number({ min: 0, max: 100 }),
so2: faker.datatype.number({ min: 0, max: 1, precision: 0.01 }),
pm2_5: faker.datatype.number({ min: 0, max: 1, precision: 0.01 }),
pm10: faker.datatype.number({ min: 0, max: 5 }),
'us-epa-index': faker.datatype.number({ min: 0, max: 5 }),
'gb-defra-index': faker.datatype.number({ min: 0, max: 5 }),
co: faker.number.int({ min: 0, max: 500 }),
no2: faker.number.float({ min: 0, max: 1, precision: 0.01 }),
o3: faker.number.int({ min: 0, max: 100 }),
so2: faker.number.float({ min: 0, max: 1, precision: 0.01 }),
pm2_5: faker.number.float({ min: 0, max: 1, precision: 0.01 }),
pm10: faker.number.int({ min: 0, max: 5 }),
'us-epa-index': faker.number.int({ min: 0, max: 5 }),
'gb-defra-index': faker.number.int({ min: 0, max: 5 }),
},
},
}
Expand Down
2 changes: 0 additions & 2 deletions cli/src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Faker } from '@faker-js/faker'

declare global {
type CommandType = 'conn' | 'pub' | 'sub' | 'benchConn' | 'benchPub' | 'benchSub' | 'simulate'

Expand Down
8 changes: 4 additions & 4 deletions cli/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
resolved "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz"
integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==

"@faker-js/faker@^7.6.0":
version "7.6.0"
resolved "https://registry.npmmirror.com/@faker-js/faker/-/faker-7.6.0.tgz"
integrity sha512-XK6BTq1NDMo9Xqw/YkYyGjSsg44fbNwYRx7QK2CuoQgyy+f1rrTDHoExVM5PsyXCtfl2vs2vVJ0MN0yN6LppRw==
"@faker-js/faker@^8.1.0":
version "8.1.0"
resolved "https://registry.yarnpkg.com/@faker-js/faker/-/faker-8.1.0.tgz#e14896f1c57af2495e341dc4c7bf04125c8aeafd"
integrity sha512-38DT60rumHfBYynif3lmtxMqMqmsOQIxQgEuPZxCk2yUYN0eqWpTACgxi0VpidvsJB8CRxCpvP7B3anK85FjtQ==

"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2":
version "1.1.2"
Expand Down
Loading