Skip to content

Commit 58ba3f6

Browse files
committed
Simplify LoadMaturityDataFromGeneratedYaml()
Include genuine teams from meta.yaml
1 parent 31f55de commit 58ba3f6

1 file changed

Lines changed: 100 additions & 107 deletions

File tree

src/app/component/circular-heatmap/circular-heatmap.component.ts

Lines changed: 100 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -95,115 +95,48 @@ export class CircularHeatmapComponent implements OnInit {
9595
`${this.perfNow()}s: LoadMaturityDataFromGeneratedYaml Downloaded`
9696
);
9797
this.YamlObject = data;
98-
var allDimensionNames = Object.keys(this.YamlObject);
99-
var totalTeamsImplemented: number = 0;
100-
var totalActivityTeams: number = 0;
101-
102-
this.AddSegmentLabels(allDimensionNames);
103-
104-
for (var l = 0; l < this.maxLevelOfActivities; l++) {
105-
for (var d = 0; d < allDimensionNames.length; d++) {
106-
var allSubDimensionInThisDimension = Object.keys(
107-
this.YamlObject[allDimensionNames[d]]
108-
);
109-
for (var s = 0; s < allSubDimensionInThisDimension.length; s++) {
110-
var allActivityInThisSubDimension = Object.keys(
111-
this.YamlObject[allDimensionNames[d]][
112-
allSubDimensionInThisDimension[s]
113-
]
98+
this.AddSegmentLabels(this.YamlObject);
99+
const localStorageData = this.getDatasetFromBrowserStorage();
100+
101+
// Initialize the card array
102+
let segmentTotalCount = this.segment_labels.length;
103+
let cardTotalCount = segmentTotalCount * this.maxLevelOfActivities;
104+
this.ALL_CARD_DATA = new Array(cardTotalCount).fill(null);
105+
106+
// Process each card / sector
107+
let subdimCount = -1;
108+
for (let dim in this.YamlObject) {
109+
for (let subdim in this.YamlObject[dim]) {
110+
subdimCount++;
111+
console.log(subdimCount, subdim);
112+
let activities: Map<number, activitySchema[]> =
113+
this.processActivities(
114+
this.YamlObject[dim][subdim],
115+
localStorageData
114116
);
115-
var level = 'Level ' + (l + 1);
116-
var activity: activitySchema[] = [];
117-
var activityCompletionStatus: number = -1;
118-
119-
for (var a = 0; a < allActivityInThisSubDimension.length; a++) {
120-
try {
121-
var uuid =
122-
this.YamlObject[allDimensionNames[d]][
123-
allSubDimensionInThisDimension[s]
124-
][allActivityInThisSubDimension[a]]['uuid'];
125-
126-
var lvlOfCurrentActivity =
127-
this.YamlObject[allDimensionNames[d]][
128-
allSubDimensionInThisDimension[s]
129-
][allActivityInThisSubDimension[a]]['level'];
130-
131-
if (lvlOfCurrentActivity == l + 1) {
132-
var nameOfActivity: string =
133-
allActivityInThisSubDimension[a];
134-
var teamStatus: { [key: string]: boolean } = {};
135-
const teams = this.teamList;
136-
137-
totalActivityTeams += 1;
138-
139-
teams.forEach((singleTeam: any) => {
140-
teamStatus[singleTeam] = false;
141-
});
142-
143-
var teamsImplemented: any =
144-
this.YamlObject[allDimensionNames[d]][
145-
allSubDimensionInThisDimension[s]
146-
][allActivityInThisSubDimension[a]]['teamsImplemented'];
147-
148-
if (teamsImplemented) {
149-
teamStatus = teamsImplemented;
150-
}
151-
152-
var localStorageData = this.getFromBrowserState();
153-
154-
if (
155-
localStorageData != null &&
156-
localStorageData.length > 0
157-
) {
158-
this.YamlObject[allDimensionNames[d]][
159-
allSubDimensionInThisDimension[s]
160-
][allActivityInThisSubDimension[a]]['teamsImplemented'] =
161-
this.getTeamImplementedFromJson(
162-
localStorageData,
163-
allActivityInThisSubDimension[a]
164-
);
165-
}
166-
167-
(
168-
Object.keys(teamStatus) as (keyof typeof teamStatus)[]
169-
).forEach((key, index) => {
170-
totalActivityTeams += 1;
171-
if (teamStatus[key] === true) {
172-
totalTeamsImplemented += 1;
173-
}
174-
});
175-
176-
activity.push({
177-
uuid: uuid,
178-
activityName: nameOfActivity,
179-
teamsImplemented: teamStatus,
180-
});
181-
}
182-
183-
if (totalActivityTeams > 0) {
184-
activityCompletionStatus =
185-
totalTeamsImplemented / totalActivityTeams;
186-
}
187-
} catch {
188-
console.log('level for activity does not exist');
189-
}
190-
}
191117

118+
for (
119+
let level: number = 1;
120+
level <= this.maxLevelOfActivities;
121+
level++
122+
) {
123+
// Create and store each card (with activities for that level)
192124
var cardSchemaData: cardSchema = {
193-
Dimension: allDimensionNames[d],
194-
SubDimension: allSubDimensionInThisDimension[s],
195-
Level: level,
196-
'Done%': activityCompletionStatus,
197-
Activity: activity,
125+
Dimension: dim,
126+
SubDimension: subdim,
127+
Level: 'Level ' + level,
128+
'Done%': -1,
129+
Activity: activities.get(level) || [],
198130
};
199131

200-
this.ALL_CARD_DATA.push(cardSchemaData);
132+
// Store cards in sequential slots, by dimension then level
133+
let levelIndex = (level - 1) * segmentTotalCount;
134+
this.ALL_CARD_DATA[levelIndex + subdimCount] = cardSchemaData;
201135
}
202136
}
203137
}
204138

205139
console.log('ALL CARD DATA', this.ALL_CARD_DATA);
206-
this.loadState();
207140
this.loadCircularHeatMap(
208141
this.ALL_CARD_DATA,
209142
'#chart',
@@ -219,6 +152,55 @@ export class CircularHeatmapComponent implements OnInit {
219152
});
220153
}
221154

155+
/**
156+
* Returns activities of one subdimension, separated by maturity level.
157+
* Source of activities is the cards from the server.
158+
*
159+
* Status of Team Implementation is merged from both server status and
160+
* locally stored changes.
161+
*/
162+
private processActivities(
163+
card: any,
164+
localStorageData: any
165+
): Map<number, activitySchema[]> {
166+
let activities: Map<number, activitySchema[]> = new Map();
167+
for (let activityName in card) {
168+
let currentActivity: any = card[activityName];
169+
let level: number = currentActivity.level;
170+
var uuid = currentActivity?.uuid;
171+
172+
// Initialize a status for all genuine teams
173+
let genuineTeams: any = {};
174+
this.teamList.forEach((singleTeam: string) => {
175+
genuineTeams[singleTeam] = false;
176+
});
177+
178+
// Read server and locally stored teams statuses as well
179+
var teamsFromYaml: any = currentActivity.teamsImplemented;
180+
var teamsFromLocalstorage: any = this.getTeamImplementedFromJson(
181+
localStorageData,
182+
activityName
183+
);
184+
185+
// Combine the lot, where local changes takes priority
186+
var combinedTeamsImplemented = Object.assign(
187+
{},
188+
genuineTeams,
189+
teamsFromYaml,
190+
teamsFromLocalstorage
191+
);
192+
193+
// Store each activity, split by maturity level
194+
if (!activities.has(level)) activities.set(level, []);
195+
activities.get(level)?.push({
196+
uuid: uuid,
197+
activityName: activityName,
198+
teamsImplemented: combinedTeamsImplemented,
199+
});
200+
}
201+
return activities;
202+
}
203+
222204
private getTeamImplementedFromJson(
223205
data: ProjectData,
224206
activityName: string
@@ -253,9 +235,17 @@ export class CircularHeatmapComponent implements OnInit {
253235
console.log(`${this.perfNow()}s: LoadTeamsFromMetaYaml Downloaded`);
254236
this.YamlObject = data;
255237

256-
this.teamList = this.YamlObject['teams'];
238+
this.teamList = this.YamlObject['teams']; // Genuine teams (the true source)
257239
this.teamGroups = this.YamlObject['teamGroups'];
258240
this.teamVisible = [...this.teamList];
241+
242+
// Ensure that all team names in the groups are genuine team names
243+
for (let team in this.teamGroups) {
244+
this.teamGroups[team] = this.teamGroups[team].filter((t: string) =>
245+
this.teamList.includes(t)
246+
);
247+
if (this.teamGroups[team].length == 0) delete this.teamGroups[team];
248+
}
259249
resolve();
260250
});
261251
});
@@ -822,22 +812,25 @@ export class CircularHeatmapComponent implements OnInit {
822812
}
823813

824814
loadState() {
825-
var content = localStorage.getItem('dataset');
815+
var content = this.getDatasetFromBrowserStorage();
816+
if (content != null) {
817+
this.ALL_CARD_DATA = content;
818+
}
819+
}
820+
821+
getDatasetFromBrowserStorage(): any {
822+
console.log(`${this.perfNow()}s: getDatasetFromBrowserStorage() ####`);
826823
// @ts-ignore
827-
if (this.ALL_CARD_DATA[0]['Task'] != null) {
824+
if (this.ALL_CARD_DATA?.length && this.ALL_CARD_DATA[0]?.Task != null) {
828825
console.log('Found outdated dataset, removing');
829826
localStorage.removeItem('dataset');
830827
}
831-
if (content != null) {
832-
this.ALL_CARD_DATA = JSON.parse(content);
833-
}
834-
}
835828

836-
getFromBrowserState(): any {
837829
var content = localStorage.getItem('dataset');
838830
if (content != null) {
839831
return JSON.parse(content);
840832
}
833+
return null;
841834
}
842835

843836
perfNow(): string {

0 commit comments

Comments
 (0)