Skip to content

Commit

Permalink
Adjusting Monthly account data and adding billing info
Browse files Browse the repository at this point in the history
  • Loading branch information
apearson committed Apr 20, 2018
1 parent a4c111a commit ee3fd0e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
14 changes: 8 additions & 6 deletions src/interfaces/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export interface DailyData{
}[];
}

export interface MonthlyData{
export interface AccountMonthlyData{
accountNumber: string;
data: {
date: Date;
kWh: number;
cost: number;
}[];
data: MonthlyData[];
}
export interface MonthlyData{
date: Date;
kWh?: number;
cost?: number;
bill?: number;
}
34 changes: 26 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fetch from 'node-fetch';
import {differenceInCalendarDays, subDays, addDays} from 'date-fns';

/* Interfaces */
import {Company, DailyData, MonthlyData, Account, UsageData} from './interfaces/general';
import {Company, DailyData, AccountMonthlyData, MonthlyData, Account, UsageData} from './interfaces/general';
import {GetAllAccountsResponse, LoginResponse, MonthlyDataResponse, DailyDataResponse} from './interfaces/responses';
import {API} from './interfaces/API';

Expand Down Expand Up @@ -411,22 +411,40 @@ export class SouthernCompanyAPI extends EventEmitter{
});
}

/* Checking to see if there is any optional data */
const kWhData = graphData.series.find((series)=> series.text === 'Usage (kWh)');
const costData = graphData.series.find((series)=> series.text === 'Service Amount (Cost $)');
const billData = graphData.series.find((series)=> series.text === 'Budget Bill Amount');

/* Mapping data to single array */
const rawMonthData = graphData['scale-x'].labels.map((date: string, index: number)=>{
const rawMonthData: MonthlyData[] = graphData['scale-x'].labels.map((date: string, index: number)=>{
const dateString = date.split('/').map((num)=> parseInt(num));
const dateObj = new Date(2000 + dateString[1], dateString[0] - 1);
return {
date: dateObj,
kWh: graphData.series[1].values[index],
cost: graphData.series[0].values[index]

/* Monthly data object */
const monthData: MonthlyData = {
date: new Date(2000 + dateString[1], dateString[0] - 1),
};

/* Adding any available data */
if(kWhData){
monthData.kWh = kWhData.values[index];
}
if(costData){
monthData.cost = costData.values[index];
}
if(billData){
monthData.bill = billData.values[index];
}

/* Returning data */
return monthData;
});

/* Filtering months with zero kWh */
const data = rawMonthData.filter((data)=> data.kWh !== 0);

/* Returning month data */
const monthlyData: MonthlyData = {
const monthlyData: AccountMonthlyData = {
accountNumber: accounts[index],
data,
};
Expand Down

0 comments on commit ee3fd0e

Please sign in to comment.