Skip to content

Commit

Permalink
change 'all time' to 'year to date' and adjust individual user logic …
Browse files Browse the repository at this point in the history
…to include older months
  • Loading branch information
benzuzu committed Mar 20, 2024
1 parent 371d716 commit f9e71ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ public ResponseEntity<UserUsage> userUsageGet(@PathVariable @NotNull Long userId
if (userId != null) {
int year = TimeUtil.getCurrentNYTime().getYear();
JSONObject yearSummary = requestData(YEAR_USERS_USAGE_SUMMARY_FILE_PREFIX + year + FileExtension.JSON_FILE.getExtension());
List<JSONObject> monthSummaries = new LinkedList<>();
Map<String, JSONObject> monthSummaries = new HashMap<>();
int monthsBack = 0;
JSONObject monthSummary;
do {
String month = TimeUtil.getCurrentNYTime().minus(monthsBack, ChronoUnit.MONTHS).format(DateTimeFormatter.ofPattern("yyyy-MM"));
monthSummary = requestData(MONTH_USERS_USAGE_SUMMARY_FILE_PREFIX + month + FileExtension.JSON_FILE.getExtension());
if (monthSummary != null) {
monthSummaries.add(monthSummary);
monthSummaries.put(month, monthSummary);
}
monthsBack++;
} while (monthsBack < 12);
Expand All @@ -99,16 +99,20 @@ public ResponseEntity<UserUsage> userUsageGet(@PathVariable @NotNull Long userId
JSONObject yearUsageObject = (JSONObject) yearSummary.get(email);
Gson gson = new Gson();
usageSummary = gson.fromJson(yearUsageObject.toString(), UsageSummary.class);
Map<String, JSONObject> dayUsage = new HashMap<>();
if (!monthSummaries.isEmpty()) {
for (JSONObject month : monthSummaries) {
if (month.containsKey(email)) {
JSONObject monthUsageObject = (JSONObject) month.get(email);
JSONObject dayUsageObject = (JSONObject) monthUsageObject.get("day");
dayUsageObject.forEach((key, value) -> dayUsage.put((String) key, (JSONObject) value));
Map<String, JSONObject> dayUsage = new HashMap<>();
Map<String, JSONObject> monthUsage = new HashMap<>();
for (Map.Entry<String, JSONObject> entry : monthSummaries.entrySet()) {
if (entry.getValue().containsKey(email)) {
JSONObject userUsageObject = (JSONObject) entry.getValue().get(email);
JSONObject dayUsageObject = (JSONObject) userUsageObject.get("day");
dayUsageObject.forEach((day, summary) -> dayUsage.put((String) day, (JSONObject) summary));
JSONObject monthUsageObject = (JSONObject) userUsageObject.get("month");
monthUsage.put((String) entry.getKey(), monthUsageObject);
}
}
usageSummary.setDay(dayUsage);
usageSummary.setMonth(monthUsage);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/config/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const SHORTEN_TEXT_FROM_LIST_THRESHOLD = 5;
export const TOKEN_ABOUT_2_EXPIRE_NOTICE_IN_DAYS = 14;
export const USAGE_TOP_USERS_LIMIT = 10000;
export const USAGE_ALL_TIME_KEY = 'All';
export const USAGE_ALL_TIME_VALUE = 'Past Year';
export const USAGE_ALL_TIME_VALUE = 'Year To Date';
export const USAGE_DETAIL_TIME_KEY = 'Detail';
export const USAGE_DAY_DETAIL_TIME_KEY = 'Day Detail';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ enum UsageType {
}

export enum ToggleValue {
ALL_USERS = 'All Users',
ALL_RESOURCES = 'All Resources',
PUBLIC_RESOURCES = 'Only Public Resources',
CUMULATIVE_USAGE = 'Cumulative Usage',
RESULTS_IN_TOTAL = 'By Year',
RESULTS_IN_TOTAL = 'Year To Date',
RESULTS_BY_MONTH = 'By Month',
RESULTS_BY_DAY = 'By Day',
}
Expand Down Expand Up @@ -119,7 +118,6 @@ export default class UsageAnalysisPage extends React.Component<{
routing: RouterStore;
match: match;
}> {
@observable topUsersToggleValue: ToggleValue = ToggleValue.ALL_USERS;
@observable userTabResourcesTypeToggleValue: ToggleValue =
ToggleValue.PUBLIC_RESOURCES;
@observable resourceTabResourcesTypeToggleValue: ToggleValue =
Expand Down Expand Up @@ -201,12 +199,6 @@ export default class UsageAnalysisPage extends React.Component<{
default: new Map(),
});

@autobind
@action
handleTopUsersToggleChange(value: ToggleValue) {
this.topUsersToggleValue = value;
}

@autobind
@action
handleUserTabResourcesTypeToggleChange(value: ToggleValue) {
Expand Down

0 comments on commit f9e71ce

Please sign in to comment.