Skip to content

Commit

Permalink
enbridge usage history csv parser
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Sep 6, 2023
1 parent 21f5935 commit 57d3e07
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 2 deletions.
3 changes: 3 additions & 0 deletions data/config.githubActions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { enbridgeUsageHistory } from '../parsers/sheetParserConfigs.js';
import baseConfig from './config.base.js';
export const config = Object.assign({}, baseConfig);
config.application.useTestDatabases = true;
Expand Down Expand Up @@ -30,4 +31,6 @@ config.tempUsers = [
password: 'p@ssw0rd'
}
];
config.parserConfigs = config.parserConfigs ?? {};
config.parserConfigs.enbridgeUsageHistory = enbridgeUsageHistory;
export default config;
6 changes: 6 additions & 0 deletions data/config.githubActions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { enbridgeUsageHistory } from '../parsers/sheetParserConfigs.js'

import baseConfig from './config.base.js'

export const config = Object.assign({}, baseConfig)
Expand Down Expand Up @@ -34,4 +36,8 @@ config.tempUsers = [
}
]

config.parserConfigs = config.parserConfigs ?? {}

config.parserConfigs.enbridgeUsageHistory = enbridgeUsageHistory

export default config
3 changes: 2 additions & 1 deletion data/config.ssm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ssmPuc } from '../parsers/sheetParserConfigs.js';
import { ssmPuc, enbridgeUsageHistory } from '../parsers/sheetParserConfigs.js';
import baseConfig from './config.base.js';
export const config = Object.assign({}, baseConfig);
config.parserConfigs = config.parserConfigs ?? {};
config.parserConfigs.ssmPuc = ssmPuc;
config.parserConfigs.enbridgeUsageHistory = enbridgeUsageHistory;
export default config;
3 changes: 2 additions & 1 deletion data/config.ssm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ssmPuc } from '../parsers/sheetParserConfigs.js'
import { ssmPuc, enbridgeUsageHistory } from '../parsers/sheetParserConfigs.js'

import baseConfig from './config.base.js'

Expand All @@ -7,5 +7,6 @@ export const config = Object.assign({}, baseConfig)
config.parserConfigs = config.parserConfigs ?? {}

config.parserConfigs.ssmPuc = ssmPuc
config.parserConfigs.enbridgeUsageHistory = enbridgeUsageHistory

export default config
1 change: 1 addition & 0 deletions parsers/parserTools.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export declare function excelDateToDate(excelDate: number): Date;
export declare function mdyToDate(mdyString: string): Date;
4 changes: 4 additions & 0 deletions parsers/parserTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ import { getJsDateFromExcel } from 'excel-date-to-js';
export function excelDateToDate(excelDate) {
return getJsDateFromExcel(excelDate);
}
export function mdyToDate(mdyString) {
const pieces = mdyString.split('/');
return new Date(Number.parseInt(pieces[2], 10), Number.parseInt(pieces[0], 10) - 1, Number.parseInt(pieces[1], 10));
}
10 changes: 10 additions & 0 deletions parsers/parserTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ import { getJsDateFromExcel } from 'excel-date-to-js'
export function excelDateToDate(excelDate: number): Date {
return getJsDateFromExcel(excelDate)
}

export function mdyToDate(mdyString: string): Date {
const pieces = mdyString.split('/')

return new Date(
Number.parseInt(pieces[2], 10),
Number.parseInt(pieces[0], 10) - 1,
Number.parseInt(pieces[1], 10)
)
}
1 change: 1 addition & 0 deletions parsers/sheetParserConfigs.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import type { ConfigParserConfiguration } from '../types/configTypes.js';
export declare const ssmPuc: ConfigParserConfiguration;
export declare const enbridgeUsageHistory: ConfigParserConfiguration;
48 changes: 48 additions & 0 deletions parsers/sheetParserConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,51 @@ export const ssmPuc = {
}
}
};
export const enbridgeUsageHistory = {
parserClass: 'SheetParser',
configName: 'Enbridge Usage History CSV',
aliasTypeKey: 'accountNumber.gas',
columns: {
assetAlias: {
dataType: 'function',
dataFunction(dataObject) {
let accountNumber = dataObject['Account Number'];
if (accountNumber.slice(-1) === "'") {
accountNumber = accountNumber.slice(0, Math.max(0, accountNumber.length - 1));
}
return accountNumber;
}
},
dataType: {
serviceCategory: {
dataType: 'value',
dataValue: 'Gas'
},
unit: {
dataType: 'value',
dataValue: 'm3'
},
commodity: {
dataType: 'value',
dataValue: 'Natural Gas'
}
},
timeSeconds: {
dataType: 'function',
dataFunction(dataObject) {
const startDate = excelDateToDate(dataObject['Billed From']);
return startDate.getTime() / 1000 + startDate.getTimezoneOffset() * 60;
}
},
durationSeconds: {
dataType: 'function',
dataFunction(dataObject) {
return dataObject['Billing Days'] * 86400;
}
},
dataValue: {
dataType: 'objectKey',
dataObjectKey: 'Consumption M3'
}
}
};
61 changes: 61 additions & 0 deletions parsers/sheetParserConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,64 @@ export const ssmPuc: ConfigParserConfiguration = {
}
}
}

interface EnbridgeUsageHistoryRowData extends Record<string, unknown> {
'Account Number': string
'Billed From': number
'Billed To': number
'Billing Days': number
'Consumption M3': string
}

export const enbridgeUsageHistory: ConfigParserConfiguration = {
parserClass: 'SheetParser',
configName: 'Enbridge Usage History CSV',
aliasTypeKey: 'accountNumber.gas',
columns: {
assetAlias: {
dataType: 'function',
dataFunction(dataObject: EnbridgeUsageHistoryRowData) {
let accountNumber = dataObject['Account Number']
if (accountNumber.slice(-1) === "'") {
accountNumber = accountNumber.slice(
0,
Math.max(0, accountNumber.length - 1)
)
}

return accountNumber
}
},
dataType: {
serviceCategory: {
dataType: 'value',
dataValue: 'Gas'
},
unit: {
dataType: 'value',
dataValue: 'm3'
},
commodity: {
dataType: 'value',
dataValue: 'Natural Gas'
}
},
timeSeconds: {
dataType: 'function',
dataFunction(dataObject: EnbridgeUsageHistoryRowData) {
const startDate = excelDateToDate(dataObject['Billed From'])
return startDate.getTime() / 1000 + startDate.getTimezoneOffset() * 60
}
},
durationSeconds: {
dataType: 'function',
dataFunction(dataObject: EnbridgeUsageHistoryRowData) {
return dataObject['Billing Days'] * 86_400
}
},
dataValue: {
dataType: 'objectKey',
dataObjectKey: 'Consumption M3'
}
}
}

0 comments on commit 57d3e07

Please sign in to comment.