Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented stats page for admins #961

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22,256 changes: 22,209 additions & 47 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"react-router-dom": "^5.1.5",
"react-scripts": "^3.4.1",
"react-select": "^2.3.0",
"recharts": "^1.4.2",
"react-table": "^6.8.6",
"react-toastify": "^7.0.4",
"styled-components": "^4.1.3",
Expand All @@ -69,6 +70,7 @@
"@types/react-select": "^2.0.11",
"@types/react-table": "^6.7.21",
"@types/react-virtualized-select": "^3.0.7",
"@types/recharts": "^1.1.6",
"@types/rebass__grid": "^6.0.2",
"@types/styled-components": "^4.1.6",
"@types/yup": "^0.26.7",
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ErrorPage from './pages/_error';
import ConfirmAccountPage from './pages/Account/Confirm';
import CreateAccountPage from './pages/Account/Create';
import EditAccountPage from './pages/Account/Edit';
import AdminSearchPage from './pages/Admin/Search';
import AdminSearchPage from './features/Search/Main';
import SettingsPage from './pages/Admin/Settings';
import ConfirmAttendancePage from './pages/Application/Confirm';
import CreateApplicationPage from './pages/Application/Create';
Expand Down Expand Up @@ -259,7 +259,7 @@ class App extends React.Component {
AuthVerification: (user: IAccount) =>
user.confirmed && user.accountType === UserType.STAFF,
}),
{ activePage: 'search' }
{ activePage: 'stats' }
)
)}
/>
Expand Down
22 changes: 17 additions & 5 deletions src/api/hacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
HackerStatus,
IHacker,
IResumeResponse,
ISearchParameter,
IStatsResponse,
} from '../config';
import LocalCache from '../util/LocalCache';
Expand Down Expand Up @@ -175,11 +176,22 @@ class HackerAPI {
return value;
}

public async getStats(): Promise<AxiosResponse<APIResponse<IStatsResponse>>> {
const key = CACHE_STATS_KEY;
const value = await API.getEndpoint(APIRoute.HACKER_STATS).getAll();
LocalCache.set(key, value, new Date(Date.now() + 5 * 60 * 1000));
return value;
public async getStats(
parameters: ISearchParameter[],
overrideCache?: boolean
): Promise<AxiosResponse<APIResponse<IStatsResponse>>> {
const model = 'hacker';
const q = JSON.stringify(parameters);
const key = `${CACHE_STATS_KEY}-${model}-${q}`;
const cached: any = LocalCache.get(key);
if (cached && !overrideCache) {
return cached as Promise<AxiosResponse<APIResponse<IStatsResponse>>>;
}
const result = await API.getEndpoint(APIRoute.HACKER_STATS).getAll({
params: { model, q },
});
LocalCache.set(key, result, new Date(Date.now() + 5 * 60 * 1000));
return result;
}
}

Expand Down
31 changes: 24 additions & 7 deletions src/api/search.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
import { AxiosPromise } from 'axios';
import { APIRoute, ISearchOptions, ISearchParameter } from '../config';
import { AxiosPromise, AxiosResponse } from 'axios';
import {
APIRoute,
CACHE_SEARCH_TABLE_KEY,
ISearchOptions,
ISearchParameter,
} from '../config';
import LocalCache from '../util/LocalCache';
import API from './api';
import APIResponse from './APIResponse';
class SearchAPI {
constructor() {
API.createEntity(APIRoute.SEARCH);
}
public search(
public async search(
model: string,
parameters: ISearchParameter[],
searchOptions: ISearchOptions
): AxiosPromise<APIResponse<any[]>> {
return API.getEndpoint(APIRoute.SEARCH).getAll({
searchOptions: ISearchOptions,
overrideCache?: boolean
): Promise<AxiosResponse<APIResponse<any[]>>> {
const q = JSON.stringify(parameters);
const key = `${CACHE_SEARCH_TABLE_KEY}-${model}-${q}`;
const cached: any = LocalCache.get(key);
if (cached && !overrideCache) {
return cached as AxiosPromise<APIResponse<any[]>>;
}
const result: AxiosResponse<APIResponse<any[]>> = await API.getEndpoint(
APIRoute.SEARCH
).getAll({
params: {
q: JSON.stringify(parameters),
q,
model,
...searchOptions,
},
});
LocalCache.set(key, result, new Date(Date.now() + 5 * 60 * 1000));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove magic numbers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or at the very least comment what they mean :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for sure!

return result;
}
}
export const Search = new SearchAPI();
Expand Down
1 change: 1 addition & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const CACHE_HACKER_KEY = 'hackerInfo';
export const CACHE_STATS_KEY = 'statsInfo';
export const CACHE_SPONSOR_KEY = 'sponsorInfo';
export const CACHE_TRAVEL_KEY = 'travelInfo';
export const CACHE_SEARCH_TABLE_KEY = 'searchTableInfo';
export const CACHE_SETTINGS_KEY = 'settingsInfo';

// General information
Expand Down
32 changes: 17 additions & 15 deletions src/config/statsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { DietaryRestriction, HackerStatus, JobInterest, ShirtSize } from '.';

export interface IStatsResponse {
stats: {
total: number;
status: { [key in HackerStatus]: number };
school: { [key: string]: number };
degree: { [key: string]: number };
gender: { [key: string]: number };
travel: { true: number; false: number };
ethnicity: { [key: string]: number };
jobInterest: { [key in JobInterest]: number };
major: { [key: string]: number };
graduationYear: { [key: string]: number };
dietaryRestriction: { [key in DietaryRestriction & string]: number };
ShirtSize: { [key in ShirtSize]: number };
age: { [key: string]: number };
};
stats: IStats;
}

export interface IStats {
total: number;
status: { [key in HackerStatus]: number };
school: { [key: string]: number };
degree: { [key: string]: number };
gender: { [key: string]: number };
needsBus: { [key: string]: number };
ethnicity: { [key: string]: number };
jobInterest: { [key in JobInterest]: number };
major: { [key: string]: number };
graduationYear: { [key: string]: number };
dietaryRestrictions: { [key in DietaryRestriction & string]: number };
shirtSize: { [key in ShirtSize]: number };
age: { [key: string]: number };
}
Loading