Skip to content

Commit

Permalink
Now can go back 3 year in usage stats
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkonecn committed Sep 18, 2024
1 parent dec09e1 commit f29064b
Show file tree
Hide file tree
Showing 8 changed files with 536 additions and 395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public Swagger2Config(ApplicationProperties applicationProperties) {
@Bean
public Docket swaggerSpringfoxApiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.forCodeGeneration(true)
.groupName("default")
.select()
.apis(RequestHandlerSelectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,6 @@ public void moveTokenStatsToS3() throws IOException {
log.info("Finished the cronjob to move token stats to s3.");
}

private void calculateUsageSummary(UsageSummary usageSummary, String key, int count, String time) {
// Deal with year summary
usageSummary.getYear().put(key, usageSummary.getYear().getOrDefault(key, Long.valueOf(0)) + count);
// Deal with month summary
if (!usageSummary.getMonth().containsKey(time)) {
usageSummary.getMonth().put(time, new JSONObject());
}
if (!usageSummary.getMonth().get(time).containsKey(key)) {
usageSummary.getMonth().get(time).put(key, new Integer(0));
}
usageSummary.getMonth().get(time).put(key, (Integer) usageSummary.getMonth().get(time).get(key) + (Integer) count);
}

/**
* {@code GET /check-trial-accounts} : Check the status of trial accounts
*/
Expand Down
674 changes: 415 additions & 259 deletions src/main/java/org/mskcc/cbio/oncokb/web/rest/UsageAnalysisController.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
package org.mskcc.cbio.oncokb.web.rest.vm.usageAnalysis;

import org.json.simple.JSONObject;

import java.util.Map;
import java.util.HashMap;

/**
* Created by Yifu Yao on 2020-10-28
*/
import java.util.Map;

public class UsageSummary {
private Map<String, JSONObject> day = new HashMap<>();
private Map<String, JSONObject> month = new HashMap<>();
private Map<String, Long> year = new HashMap<>();
private Map<String, Map<String, Long>> day = new HashMap<>();

public Map<String, JSONObject> getDay() {
return day;
}
private Map<String, Map<String, Long>> month = new HashMap<>();

public void setDay(Map<String, JSONObject> day) {
this.day = day;
}
private Map<String, Map<String, Long>> year = new HashMap<>();

public Map<String, JSONObject> getMonth() {
return month;
}
public Map<String, Map<String, Long>> getDay() {
return day;
}

public void setMonth(Map<String, JSONObject> month) {
this.month = month;
}
public void setDay(Map<String, Map<String, Long>> day) {
this.day = day;
}

public Map<String, Long> getYear() {
return year;
}
public Map<String, Map<String, Long>> getMonth() {
return month;
}

public void setYear(Map<String, Long> year) {
this.year = year;
}
public void setMonth(Map<String, Map<String, Long>> month) {
this.month = month;
}

public Map<String, Map<String, Long>> getYear() {
return year;
}

public void setYear(Map<String, Map<String, Long>> year) {
this.year = year;
}
}
26 changes: 19 additions & 7 deletions src/main/webapp/app/pages/usageAnalysisPage/UsageAnalysisPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,25 @@ export default class UsageAnalysisPage extends React.Component<{
const result = new Map<string, UsageRecord[]>();
const yearSummary = resource.year;
const yearUsage: UsageRecord[] = [];
Object.keys(yearSummary).forEach(resourceEntry => {
yearUsage.push({
resource: resourceEntry,
usage: yearSummary[resourceEntry],
time: '',
});
});
const [, currentYearSummary] = Object.entries(yearSummary).reduce(
([year, obj], [newYear, newObj]): [string, Record<string, number>] => {
if (+year < +newYear) {
return [newYear, newObj as Record<string, number>];
} else {
return [year, obj as Record<string, number>];
}
},
['0', {}]
);
Object.entries(currentYearSummary as Record<string, number>).forEach(
([resourceEntry, usage]: [string, number]) => {
yearUsage.push({
resource: resourceEntry,
usage,
time: '',
});
}
);
result.set(USAGE_ALL_TIME_KEY, yearUsage);
this.dropdownList.push(USAGE_ALL_TIME_KEY);

Expand Down
60 changes: 37 additions & 23 deletions src/main/webapp/app/shared/api/generated/API-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2963,9 +2963,6 @@
"apiAccessRequest": {
"$ref": "#/definitions/ApiAccessRequest"
},
"sentToRocReview": {
"type": "boolean"
},
"trialAccount": {
"$ref": "#/definitions/TrialAccount"
},
Expand Down Expand Up @@ -3167,13 +3164,6 @@
},
"title": "Contact"
},
"JSONObject": {
"type": "object",
"title": "JSONObject",
"additionalProperties": {
"type": "object"
}
},
"KeyAndPasswordVM": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -3379,9 +3369,6 @@
"maxLength": 50,
"pattern": "^[_.\\-\\+@A-Za-z0-9]*$"
},
"needsMskRocReview": {
"type": "boolean"
},
"notifyUserOnTrialCreation": {
"type": "boolean"
},
Expand All @@ -3407,6 +3394,14 @@
},
"title": "ManagedUserVM"
},
"MapOfstringAndlong": {
"type": "object",
"title": "MapOfstringAndlong",
"additionalProperties": {
"type": "integer",
"format": "int64"
}
},
"PasswordChangeDTO": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -3479,7 +3474,8 @@
"additionalProperties": {
"type": "object",
"additionalProperties": {
"type": "object"
"type": "integer",
"format": "int64"
}
}
},
Expand All @@ -3488,15 +3484,19 @@
"additionalProperties": {
"type": "object",
"additionalProperties": {
"type": "object"
"type": "integer",
"format": "int64"
}
}
},
"year": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "int64"
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "int64"
}
}
}
},
Expand Down Expand Up @@ -3798,19 +3798,33 @@
"UserOverviewUsage": {
"type": "object",
"properties": {
"dayUsage": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "int64"
}
},
"endpoint": {
"type": "string"
},
"maxUsage": {
"type": "integer",
"format": "int64"
"maxUsageProportion": {
"type": "number",
"format": "float"
},
"monthUsage": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "int64"
}
},
"noPrivateEndpoint": {
"type": "string"
},
"noPrivateMaxUsage": {
"type": "integer",
"format": "int64"
"noPrivateMaxUsageProportion": {
"type": "number",
"format": "float"
},
"totalUsage": {
"type": "integer",
Expand Down
20 changes: 8 additions & 12 deletions src/main/webapp/app/shared/api/generated/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export type Activation = {
export type AdditionalInfoDTO = {
'apiAccessRequest': ApiAccessRequest

'sentToRocReview': boolean

'trialAccount': TrialAccount

'userCompany': UserCompany
Expand Down Expand Up @@ -89,7 +87,6 @@ export type Contact = {
'phone': string

};
export type JSONObject = {};
export type KeyAndPasswordVM = {
'key': string

Expand Down Expand Up @@ -169,8 +166,6 @@ export type ManagedUserVM = {

'login': string

'needsMskRocReview': boolean

'notifyUserOnTrialCreation': boolean

'password': string
Expand All @@ -184,6 +179,7 @@ export type ManagedUserVM = {
'tokenValidDays': number

};
export type MapOfstringAndlong = {};
export type PasswordChangeDTO = {
'currentPassword': string

Expand Down Expand Up @@ -343,12 +339,16 @@ export type UserMailsDTO = {

};
export type UserOverviewUsage = {
'endpoint': string
'dayUsage': {}

'noPrivateEndpoint': string
'endpoint': string

'maxUsageProportion': number

'monthUsage': {}

'noPrivateEndpoint': string

'noPrivateMaxUsageProportion': number

'totalUsage': number
Expand All @@ -357,10 +357,6 @@ export type UserOverviewUsage = {

'userId': string

'dayUsage': {}

'monthUsage': {}

};
export type UserUsage = {
'company': string
Expand Down Expand Up @@ -5729,4 +5725,4 @@ export default class API {
return response.body;
});
};
}
}
Loading

0 comments on commit f29064b

Please sign in to comment.