-
Notifications
You must be signed in to change notification settings - Fork 1
Phase1 design
Transform eGauge CSV files to device files.
An eGauge CSV file corresponds to a single eGauge and all the devices it monitors. The header row consists of Date&Time, Device1 description, Device2 description,... The data in the first column is the timestamp. The data in the remaining columns is the Wh power consumption value of the corresponding device at the corresponding timestamp.
The device file is a tentative format.
One device file will be created for each device monitored by an eGauge.
The first line will be a metadata object written in JSON.
{"eGaugeName": "eGauge001", "deviceDescription": "A/C", "label": "air_conditioner"}
, for example.
The following lines will be timestamp Wh_value
.
If a function name is indented, then the previously less indented function calls that more indented function.
[]
means a list.
main([arg])
parseArgs([arg]) -> dirCsv
filesInDir(dirCsv) -> [fileName]
extractMetadata(fileName) -> [metadata]
descriptionToLabel(description) -> label
writeDeviceInfo(fileName, [metadata]) -> None
openFiles([fileName]) -> [filePointer]
closeFiles([file]) -> None
- main
- Input - [string] List of command line arguments from sys.argv.
- Output - Nothing. Has a side effect of creating the desired device files.
- Description - Accomplishes the goal of Phase 1.
- parseArgs (optional for documentation purposes)
- Input - [string] - arguments
- Output - Object with an attribute corresponding to the expected command line argument, which is a directory path.
- Description - Using the Python argparse library is great for documentation. It describes the program to the end user. It also tells them exactly what command line arguments are expected. This will simply take sys.agv and transform it into an object that has an attribute which is a directory path string.
- filesInDir
- Input - string - directory path
- Output - [string] - file names
- Description - Given a directory path, returns a list of all the full paths of all files in that directory.
- extractMetadata
- Input - string - file name
- Output - [metadata objects] Could be a list of objects or Python dicts.
- Description - Creates metadata objects from the first line of the given CSV file.
- descriptionToLabel
- Input - string - description of a device connect to the eGauga.
- Output - string - accepted label for the device.
- Description - Converts a device description in the header of the eGauge CSV file to a label corresponding to device of that type.
- writeDeviceInfo
- Input - string,[metadata objects] - the full path of the file name of the eGauge CSV file, a list of metadata objects representing each device monitored by the eGauge.
- Output - None - there's no real output only the side effect of creating the desired output files.
- Description - Reads from the second line of the eGauge CSV file. Writes the metadata and (time, wH values) to the desired output files.
- openFiles
- Input - [sting] - a list of file names.
- Output - [file] - a list of file pointers.
- Description - opens a file in write mode for each file name given.
- closeFiles
- Input - [file] - a list of file names.
- Output - None - has side effect of closing all files.
- Description - closes all files.