Skip to content

Commit

Permalink
refactor(script): update the simulate script
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream committed Apr 3, 2024
1 parent cdb75fc commit 95cb809
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion scripts-example/IoT-data-scenarios/IEM.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
const calculateEnergyConsumption = (faker, maxPower) => {
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 scripts-example/IoT-data-scenarios/smart_home.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ const generateRoomData = (faker, roomType) => {

const baseData = {
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) {
return {
...baseData,
fridge_temperature: faker.datatype.number({ min: 2, max: 8 }),
fridge_temperature: faker.number.int({ min: 2, max: 8 }),
oven_on: faker.datatype.boolean(),
}
}
Expand All @@ -47,7 +47,7 @@ const generateRoomData = (faker, roomType) => {
return {
...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 }),
}
}

Expand All @@ -65,9 +65,9 @@ const generator = (faker, options) => {
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 scripts-example/IoT-data-scenarios/tesla.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ const generator = (faker, options) => {
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(),
}
}
const data = {
Expand All @@ -43,13 +43,13 @@ const generator = (faker, options) => {
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 @@ -58,30 +58,30 @@ const generator = (faker, options) => {
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 scripts-example/IoT-data-scenarios/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ const generator = (faker, options) => {
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 @@ -76,40 +76,40 @@ const generator = (faker, options) => {
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

0 comments on commit 95cb809

Please sign in to comment.