Created
August 15, 2020 15:29
-
-
Save JaneJeon/6adc4da2267474b036be60c8718d1820 to your computer and use it in GitHub Desktop.
Clean up/ingest DTE Energy's detailed energy report CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This baby can transform CSVs no matter how large they are through the magic of streaming! | |
// You can clean up DTE Energy report CSV as follows: | |
// cat electric_usage_report_11-08-2019_to_08-13-2020.csv | node transform.js > energy-report.csv | |
import csv from "csv" | |
const parser = csv.parse({ columns: true }) | |
const transformer = csv.transform(data => { | |
const date = data["Day"].split("/") | |
return { | |
account: data["Account Number"], | |
year: date[2], | |
month: date[0], | |
day: date[1], | |
hour: data["Hour of Day"], | |
kWh: data["Hourly Total"], | |
} | |
}) | |
const stringifier = csv.stringify({ header: true }) | |
process.stdin | |
.pipe(parser) | |
.pipe(transformer) | |
.pipe(stringifier) | |
.pipe(process.stdout) // streamsssss baby baby! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment