2.0.11 • Published 5 months ago

powerdatautils v2.0.11

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

This library offers a collection of utilities to simulate and transform data, particularly useful for scenarios involving energy consumption data simulation and general data transformation. The library includes two main modules: DataSimulator and DataTransformer.

Installation To install the library, run the following command in your project directory:

npm install datapowerutils

Modules

DataSimulator is a utility class for generating simulated energy consumption data.

Usage

import DataSimulator from powerdatautils/DataSimulator;
const simulatedData = DataSimulator.generateElectricityUnits(hours, peakHours, avgConsumption);

Methods

generateElectricityUnits(hours, peakHours, avgConsumption)

hours: Number of hours for which data is to be generated. peakHours: Object specifying the start and end of peak hours ({ start: number, end: number }). avgConsumption: Object specifying average consumption rates during peak and off-peak hours ({ peak: number, offPeak: number }).

Returns an array of numbers representing simulated energy consumption for each hour.

DataTransformer is a utility class for sorting arrays of objects.

import DataTransformer from powerdatautils/DataTransformer;
const sortedData = DataTransformer.sortData(dataArray, sortByKey, isAscending);

Usage

import DataTransformer from powerdatautils/DataTransformer;
const sortedData = DataTransformer.sortData(dataArray, sortByKey, isAscending);

Methods

sortData(data, sortBy, ascending)

data: Array of objects to be sorted.

sortBy: Key in the objects to sort by.

ascending: Boolean indicating whether the sort should be ascending (true) or descending (false). Defaults to true. Returns the sorted array of objects.

Examples Simulating Energy Consumption Data

const hours = 24;
const peakHours = { start: 17, end: 21 };
const avgConsumption = { peak: 10, offPeak: 3 };
const energyData = DataSimulator.generateElectricityUnits(hours, peakHours, avgConsumption);
console.log(energyData);

Sorting Data

const users = [
  { name: 'Alice', age: 30 },
  { name: 'Bob', age: 25 },
  { name: 'Carol', age: 35 }
];
const sortedUsers = DataTransformer.sortData(users, 'age');
console.log(sortedUsers);

Contributing Contributions to improve the library are welcome. Please ensure that your code adheres to the existing style and that all tests pass.

License This project is licensed under the MIT License.

2.0.11

5 months ago

2.0.10

5 months ago

2.0.9

5 months ago

2.0.8

5 months ago

2.0.7

5 months ago

2.0.6

5 months ago

2.0.5

5 months ago

2.0.4

5 months ago

2.0.3

5 months ago

2.0.2

5 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago