Skip to content
Snippets Groups Projects
Commit 503d2bd5 authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

format dataconversion file

parent 61c62414
No related branches found
No related tags found
1 merge request!6Feature/comp 125 staffing graph
......@@ -7,7 +7,7 @@ import {
ChargingStructureDataset, Budget, BasicDataset
} from "../Schema";
const DEFAULT_CHARGING_STRUCTURE_DATA = [
const DEFAULT_CHARGING_STRUCTURE_DATA = [
{
"NREN": "",
"YEAR": 0,
......@@ -16,18 +16,18 @@ const DEFAULT_CHARGING_STRUCTURE_DATA = [
]
// create a color from a string, credits https://stackoverflow.com/a/16348977
const stringToColour = function(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
let colour = '#';
for (let i = 0; i < 3; i++) {
const value = (hash >> (i * 8)) & 0xFF;
const valueAsString = '00' + value.toString(16);
colour += valueAsString.substring(valueAsString.length - 2);
}
return colour;
const stringToColour = function (str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
let colour = '#';
for (let i = 0; i < 3; i++) {
const value = (hash >> (i * 8)) & 0xFF;
const valueAsString = '00' + value.toString(16);
colour += valueAsString.substring(valueAsString.length - 2);
}
return colour;
}
function getColorMap() {
......@@ -118,8 +118,8 @@ export const createFundingSourceDataset = (fundingSourcesData: FundingSource[])
function createBudgetDataLookup(budgetEntries: Budget[]) {
const dataLookup = new Map<string, number>();
budgetEntries.forEach((item: Budget) => {
const lookupKey = `${item.NREN}/${item.BUDGET_YEAR}`;
dataLookup.set(lookupKey, Number(item.BUDGET));
const lookupKey = `${item.NREN}/${item.BUDGET_YEAR}`;
dataLookup.set(lookupKey, Number(item.BUDGET));
})
return dataLookup;
}
......@@ -151,38 +151,38 @@ export function createBudgetDataset(budgetEntries: Budget[]): BasicDataset {
function createChargingStructureDataLookup(data: ChargingStructure[]) {
const dataLookup = new Map<string, (string|null)>();
const dataLookup = new Map<string, (string | null)>();
data.forEach((item: ChargingStructure) => {
const lookupKey = `${item.NREN}/${item.YEAR}`
dataLookup.set(lookupKey, item.FEE_TYPE)
const lookupKey = `${item.NREN}/${item.YEAR}`
dataLookup.set(lookupKey, item.FEE_TYPE)
})
return dataLookup;
}
export function coordinateLookupForFeeStructure(feeType:string,nren:string,
yearIndex:number,nrenIndex:number){
switch(feeType){
export function coordinateLookupForFeeStructure(feeType: string, nren: string,
yearIndex: number, nrenIndex: number) {
switch (feeType) {
case "flat_fee":
return {x:(0+((yearIndex+1)*2)),y:(nrenIndex+1),feeType:feeType}
return { x: (0 + ((yearIndex + 1) * 2)), y: (nrenIndex + 1), feeType: feeType }
case "usage_based_fee":
return {x:(5+((yearIndex+1)*2)),y:(nrenIndex+1),feeType:feeType}
return { x: (5 + ((yearIndex + 1) * 2)), y: (nrenIndex + 1), feeType: feeType }
case "combination":
return {x:(10+((yearIndex+1)*2)),y:(nrenIndex+1),feeType:feeType}
return { x: (10 + ((yearIndex + 1) * 2)), y: (nrenIndex + 1), feeType: feeType }
case "no_charge":
return {x:(15+((yearIndex+1)*2)),y:(nrenIndex+1),feeType:feeType}
return { x: (15 + ((yearIndex + 1) * 2)), y: (nrenIndex + 1), feeType: feeType }
case "other":
return {x:(20+((yearIndex+1)*2)),y:(nrenIndex+1),feeType:feeType}
return { x: (20 + ((yearIndex + 1) * 2)), y: (nrenIndex + 1), feeType: feeType }
default:
return {x:0,y:(nrenIndex+1),feeType:feeType}
return { x: 0, y: (nrenIndex + 1), feeType: feeType }
}
}
export function lookupColorForNRENYear(feeType:string,yearIndex:number){
if(feeType === ""){
export function lookupColorForNRENYear(feeType: string, yearIndex: number) {
if (feeType === "") {
return "rgba(0, 0, 0, 0)"
}else{
switch(yearIndex){
} else {
switch (yearIndex) {
case 0:
return "rgba(244, 144, 28, 1)"
case 1:
......@@ -191,7 +191,7 @@ export function lookupColorForNRENYear(feeType:string,yearIndex:number){
return "rgba(0, 0, 0, 0)"
}
}
}
export function createChargingStructureDataset(chargingStructureData: ChargingStructure[]) {
const data = chargingStructureData ?? DEFAULT_CHARGING_STRUCTURE_DATA;
......@@ -200,31 +200,31 @@ export function createChargingStructureDataset(chargingStructureData: ChargingSt
const labelsNREN = [...new Set(data.map((item: ChargingStructure) => item.NREN))];
const labelsYear = [...new Set(data.map((item: ChargingStructure) => item.YEAR))];
const sizeOfYear = labelsYear.length;
const chargingStructureDataset = labelsYear.map(function (year,yearIndex) {
const chargingStructureDataset = labelsYear.map(function (year, yearIndex) {
return {
label: "(" + year + ")",
data: labelsNREN.map((nren,nrenIndex) => {
data: labelsNREN.map((nren, nrenIndex) => {
// ensure that the data is in the same order as the labels
const lookupKey = `${nren}/${year}`
const fee_type =dataLookup.get(lookupKey) ?? ""
return coordinateLookupForFeeStructure(fee_type,nren,yearIndex,nrenIndex)
const fee_type = dataLookup.get(lookupKey) ?? ""
return coordinateLookupForFeeStructure(fee_type, nren, yearIndex, nrenIndex)
}),
pointBorderColor : labelsNREN.map((nren,nrenIndex) => {
pointBorderColor: labelsNREN.map((nren, nrenIndex) => {
// ensure that the data is in the same order as the labels
const lookupKey = `${nren}/${year}`
const fee_type =dataLookup.get(lookupKey) ?? ""
return lookupColorForNRENYear(fee_type,yearIndex)
const fee_type = dataLookup.get(lookupKey) ?? ""
return lookupColorForNRENYear(fee_type, yearIndex)
}),
pointRadius:20,
pointRadius: 20,
usePointStyle: true,
pointStyle: 'rectRounded',
pointBackgroundColor: labelsNREN.map((nren,nrenIndex) => {
pointStyle: 'rectRounded',
pointBackgroundColor: labelsNREN.map((nren, nrenIndex) => {
// ensure that the data is in the same order as the labels
const lookupKey = `${nren}/${year}`
const fee_type =dataLookup.get(lookupKey) ?? ""
return lookupColorForNRENYear(fee_type,yearIndex)
const fee_type = dataLookup.get(lookupKey) ?? ""
return lookupColorForNRENYear(fee_type, yearIndex)
}),
borderRadius: 0,
......@@ -235,12 +235,12 @@ export function createChargingStructureDataset(chargingStructureData: ChargingSt
}
}
)
const dataResponse: ChargingStructureDataset = {
datasets: chargingStructureDataset,
labels: labelsNREN.map(l => l.toString())
}
return dataResponse;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment