Skip to content

Commit

Permalink
Filter by date in users tab
Browse files Browse the repository at this point in the history
  • Loading branch information
benzuzu committed Aug 2, 2023
1 parent 88d9e6f commit ffdd393
Show file tree
Hide file tree
Showing 7 changed files with 417 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,22 @@ public ResponseEntity<List<UserOverviewUsage>> userOverviewUsageGet(@RequestPara
HttpStatus status = HttpStatus.OK;

int year = TimeUtil.getCurrentNYTime().getYear();
JSONObject jsonObject = requestData(YEAR_USERS_USAGE_SUMMARY_FILE_PREFIX + year + FileExtension.JSON_FILE.getExtension());
JSONObject yearSummary = requestData(YEAR_USERS_USAGE_SUMMARY_FILE_PREFIX + year + FileExtension.JSON_FILE.getExtension());
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.put(month, monthSummary);
}
monthsBack++;
} while (monthsBack < 12);

List<UserOverviewUsage> result = new ArrayList<>();
if (jsonObject != null) {
Set<Object> emailSet = jsonObject.keySet();
if (yearSummary != null) {
Set<Object> emailSet = yearSummary.keySet();
if (companyId != null) {
emailSet = emailSet.stream().filter(item -> {
Optional<User> user = userService.getUserWithAuthoritiesByEmailIgnoreCase((String) item);
Expand All @@ -158,7 +169,7 @@ public ResponseEntity<List<UserOverviewUsage>> userOverviewUsageGet(@RequestPara
}
for (Object item : emailSet) {
String email = (String) item;
JSONObject usageObject = (JSONObject) jsonObject.get(email);
JSONObject usageObject = (JSONObject) yearSummary.get(email);
Gson gson = new Gson();
UsageSummary usageSummary = gson.fromJson(usageObject.toString(), UsageSummary.class);
UserOverviewUsage cur = new UserOverviewUsage();
Expand Down Expand Up @@ -187,9 +198,34 @@ public ResponseEntity<List<UserOverviewUsage>> userOverviewUsageGet(@RequestPara
}
cur.setTotalUsage(totalUsage);
cur.setEndpoint(endpoint);
cur.setMaxUsage(maxUsage);
cur.setMaxUsageProportion((int) (1000 * ((float) maxUsage / totalUsage)) / 10f);
cur.setNoPrivateEndpoint(noPrivateEndpoint);
cur.setNoPrivateMaxUsage(noPrivateMaxUsage);
cur.setNoPrivateMaxUsageProportion((int) (1000 * ((float) noPrivateMaxUsage / totalUsage)) / 10f);

Map<String, Long> dayUsage = new HashMap<>();
Map<String, Long> monthUsage = new HashMap<>();
if (!monthSummaries.isEmpty()) {
for (Map.Entry<String, JSONObject> entry : monthSummaries.entrySet()) {
if (entry.getValue().containsKey(email)) {
JSONObject monthUsageObject = (JSONObject) entry.getValue().get(email);
long monthCount = 0;
JSONObject dayUsageObject = (JSONObject) monthUsageObject.get("day");
for (Object dayKey : dayUsageObject.keySet()) {
String day = dayKey.toString();
JSONObject curDayUsage = (JSONObject) dayUsageObject.get(day);
long dayCount = 0;
for (Object resource : curDayUsage.keySet()) {
dayCount += (long) curDayUsage.get(resource);
monthCount += (long) curDayUsage.get(resource);
}
dayUsage.put(day, dayCount);
}
monthUsage.put(entry.getKey(), monthCount);
}
}
}
cur.setDayUsage(dayUsage);
cur.setMonthUsage(monthUsage);

result.add(cur);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.mskcc.cbio.oncokb.web.rest.vm.usageAnalysis;

import java.util.Map;

/**
* Created by Yifu Yao on 2020-11-2
*/
Expand All @@ -9,9 +11,11 @@ public class UserOverviewUsage {
private String userEmail;
private String endpoint;
private String noPrivateEndpoint;
private long maxUsage;
private long noPrivateMaxUsage;
private float maxUsageProportion;
private float noPrivateMaxUsageProportion;
private long totalUsage;
private Map<String, Long> dayUsage;
private Map<String, Long> monthUsage;

public String getEndpoint() {
return endpoint;
Expand All @@ -29,12 +33,12 @@ public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}

public long getMaxUsage() {
return maxUsage;
public float getMaxUsageProportion() {
return maxUsageProportion;
}

public void setMaxUsage(long maxUsage) {
this.maxUsage = maxUsage;
public void setMaxUsageProportion(float maxUsageProportion) {
this.maxUsageProportion = maxUsageProportion;
}

public long getTotalUsage() {
Expand All @@ -61,12 +65,28 @@ public void setNoPrivateEndpoint(String noPrivateEndpoint) {
this.noPrivateEndpoint = noPrivateEndpoint;
}

public long getNoPrivateMaxUsage() {
return noPrivateMaxUsage;
public float getNoPrivateMaxUsageProportion() {
return noPrivateMaxUsageProportion;
}

public void setNoPrivateMaxUsageProportion(float noPrivateMaxUsageProportion) {
this.noPrivateMaxUsageProportion = noPrivateMaxUsageProportion;
}

public Map<String, Long> getDayUsage() {
return dayUsage;
}

public void setDayUsage(Map<String, Long> dayUsage) {
this.dayUsage = dayUsage;
}

public Map<String, Long> getMonthUsage() {
return monthUsage;
}

public void setNoPrivateMaxUsage(long noPrivateMaxUsage) {
this.noPrivateMaxUsage = noPrivateMaxUsage;
public void setMonthUsage(Map<String, Long> monthUsage) {
this.monthUsage = monthUsage;
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import OncoKBTable from 'app/components/oncokbTable/OncoKBTable';
import { filterByKeyword } from 'app/shared/utils/Utils';
import autobind from 'autobind-decorator';
import _ from 'lodash';
import { action, observable } from 'mobx';
import { observer } from 'mobx-react';
import React from 'react';
Expand Down Expand Up @@ -55,8 +54,8 @@ export default class ResourceUsageDetailsTable extends React.Component<
{
...getUsageTableColumnDefinition(UsageTableColumnKey.RESOURCES),
Header: emailHeader,
onFilter: (data: UsageRecord, keyword) =>
filterByKeyword(data.resource, keyword),
onFilter: (row: UsageRecord, keyword) =>
filterByKeyword(row.resource, keyword),
},
{
...getUsageTableColumnDefinition(UsageTableColumnKey.USAGE),
Expand All @@ -67,8 +66,8 @@ export default class ResourceUsageDetailsTable extends React.Component<
{
...getUsageTableColumnDefinition(UsageTableColumnKey.TIME),
Header: filterDependentTimeHeader(this.timeTypeToggleValue),
onFilter: (data: UsageRecord, keyword) =>
filterByKeyword(data.time, keyword),
onFilter: (row: UsageRecord, keyword) =>
filterByKeyword(row.time, keyword),
},
]}
loading={this.props.loadedData ? false : true}
Expand Down
115 changes: 10 additions & 105 deletions src/main/webapp/app/pages/usageAnalysisPage/UsageAnalysisPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,21 @@ import autobind from 'autobind-decorator';
import { Row, Dropdown, DropdownButton } from 'react-bootstrap';
import {
PAGE_ROUTE,
USAGE_TOP_USERS_LIMIT,
USAGE_ALL_TIME_KEY,
} from 'app/config/constants';
import { remoteData } from 'cbioportal-frontend-commons';
import * as QueryString from 'query-string';
import { UsageToggleGroup } from './UsageToggleGroup';
import { TableCellRenderer } from 'react-table';
import {
emailHeader,
endpointHeader,
noPrivateEndpointHeader,
operationHeader,
resourceHeader,
timeHeader,
usageHeader,
filterDependentResourceHeader,
} from 'app/components/oncokbTable/HeaderConstants';
import UsageText from 'app/shared/texts/UsageText';
import UsageAnalysisTable from "app/pages/usageAnalysisPage/UsageAnalysisTable";

export type UsageRecord = {
resource: string;
Expand All @@ -56,7 +53,6 @@ enum UsageType {

export enum ToggleValue {
ALL_USERS = 'All Users',
TOP_USERS = 'Top Users',
ALL_RESOURCES = 'All Resources',
PUBLIC_RESOURCES = 'Only Public Resources',
CUMULATIVE_USAGE = 'Cumulative Usage',
Expand Down Expand Up @@ -257,102 +253,11 @@ export default class UsageAnalysisPage extends React.Component<{
>
<Tab eventKey={UsageType.USER} title="Users">
<div className="mt-2">
<OncoKBTable
data={
this.topUsersToggleValue === ToggleValue.ALL_USERS
? this.users.result
: _.filter(this.users.result, function (user) {
return user.totalUsage >= USAGE_TOP_USERS_LIMIT;
})
}
columns={[
{
id: 'userEmail',
Header: emailHeader,
accessor: 'userEmail',
minWidth: 200,
onFilter: (data: UserOverviewUsage, keyword) =>
filterByKeyword(data.userEmail, keyword),
},
{
id: 'totalUsage',
Header: usageHeader,
minWidth: 100,
accessor: 'totalUsage',
Cell(props: { original: UserOverviewUsage }) {
return <UsageText usage={props.original.totalUsage} />;
},
},
this.userTabResourcesTypeToggleValue ===
ToggleValue.ALL_RESOURCES
? {
id: 'endpoint',
Header: endpointHeader,
minWidth: 200,
accessor: 'endpoint',
onFilter: (data: UserOverviewUsage, keyword) =>
filterByKeyword(data.endpoint, keyword),
}
: {
id: 'noPrivateEndpoint',
Header: noPrivateEndpointHeader,
minWidth: 200,
accessor: 'noPrivateEndpoint',
onFilter: (data: UserOverviewUsage, keyword) =>
filterByKeyword(data.noPrivateEndpoint, keyword),
},
{
...getUsageTableColumnDefinition(
UsageTableColumnKey.OPERATION
),
sortable: false,
className: 'd-flex justify-content-center',
Cell(props: { original: UserOverviewUsage }) {
return (
props.original.userId && (
<Link
to={`${PAGE_ROUTE.ADMIN_USER_USAGE_DETAILS_LINK}${props.original.userId}`}
>
<i className="fa fa-info-circle"></i>
</Link>
)
);
},
},
]}
loading={this.users.isPending}
defaultSorted={[
{
id: 'totalUsage',
desc: true,
},
]}
showPagination={true}
minRows={1}
filters={() => {
return (
<Row>
<UsageToggleGroup
defaultValue={this.topUsersToggleValue}
toggleValues={[
ToggleValue.ALL_USERS,
ToggleValue.TOP_USERS,
]}
handleToggle={this.handleTopUsersToggleChange}
/>
<UsageToggleGroup
defaultValue={this.userTabResourcesTypeToggleValue}
toggleValues={[
ToggleValue.ALL_RESOURCES,
ToggleValue.PUBLIC_RESOURCES,
]}
handleToggle={
this.handleUserTabResourcesTypeToggleChange
}
/>
</Row>
);
}}
<UsageAnalysisTable
data={this.users.result}
loadedData={this.users.isComplete}
defaultResourcesType={ToggleValue.PUBLIC_RESOURCES}
defaultTimeType={ToggleValue.RESULTS_BY_DAY}
/>
</div>
</Tab>
Expand All @@ -368,8 +273,8 @@ export default class UsageAnalysisPage extends React.Component<{
Header: filterDependentResourceHeader(
this.resourceTabResourcesTypeToggleValue
),
onFilter: (data: UsageRecord, keyword) =>
filterByKeyword(data.resource, keyword),
onFilter: (row: UsageRecord, keyword) =>
filterByKeyword(row.resource, keyword),
},
{
...getUsageTableColumnDefinition(UsageTableColumnKey.USAGE),
Expand All @@ -392,13 +297,13 @@ export default class UsageAnalysisPage extends React.Component<{
props.original.resource
)}`}
>
<i className="fa fa-info-circle"></i>
<i className="fa fa-info-circle"/>
</Link>
);
},
},
]}
loading={this.usageDetail.isComplete ? false : true}
loading={!this.usageDetail.isComplete}
defaultSorted={[
{
id: UsageTableColumnKey.USAGE,
Expand Down
Loading

0 comments on commit ffdd393

Please sign in to comment.