Skip to content

Commit

Permalink
51 add trends per role std dev and variance metric (#102)
Browse files Browse the repository at this point in the history
* add flatten func and endpoint for std dev trends

* if color not found use default color logic

* add fetch and line chart for new chart
  • Loading branch information
thearyadev committed Jan 19, 2024
1 parent 972151b commit a7674e2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/app/components/charts/lineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const LineChart = (props: LineChartProps) => {
max: 9
},
series: data.map(item => ({
color: HeroColors[item.name],
color: HeroColors[item.name] ?? null,
type: "line",
...item
})),
Expand Down
10 changes: 8 additions & 2 deletions frontend/pages/trends.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ export type TrendLine = {
}


const Trends = ({data, season_list}: {data: TrendLine[], season_list: string[]}) => {
const Trends = ({data, season_list, std_dev_data}: {data: TrendLine[], season_list: string[], std_dev_data: TrendLine[]}) => {
return (
<>
<Card title={"Seasonal Trends"} nowrap>
<LineChart data={data} seasons={season_list} title={"Occurrences: All Roles All Regions"} />
<LineChart title={"Standard Deviation: By Role All Regions"} data={std_dev_data} seasons={season_list} />

</Card>
</>
)
Expand All @@ -26,13 +28,17 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
const res2 = await fetch("http://server:8000/d/seasons")
const season_list = await res2.json()

const res3 = await fetch("http://server:8000/d/all_seasons_std_by_role")
const std_dev_data = await res3.json()

return {
props: {
data,
season_list,
std_dev_data,
},
};
}


export default Trends;
export default Trends;
26 changes: 26 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ def std_dev_data() -> dict[str, dict[str, float]]:
def filter_fn(percentile):
def filter_fn_inner(x):
return x > percentile

return filter_fn_inner

exclude_percentile = 10
support = list(filter(filter_fn(np.percentile(support, exclude_percentile)), support))
damage = list(filter(filter_fn(np.percentile(damage, exclude_percentile)), damage))
Expand All @@ -454,18 +456,42 @@ def filter_fn_inner(x):
return result


def std_dev_data_flatten(data: dict[str, dict[str, float]]):
result_pre = dict(SUPPORT=list(), DAMAGE=list(), TANK=list())
for roles_and_std_dev in data.values():
for role, std_dev in roles_and_std_dev.items():
result_pre[role].append(std_dev)
result: list[dict[str, list[float] | str]] = list()
for key, val in result_pre.items():
result.append(
{"name": key, "data": val}
)

return result


@app.get("/d/seasons")
async def seasons_list_d():
return Response(json.dumps(seasons_list()), media_type="application/json")


std_dev_data_flatten(std_dev_data())


@app.get("/d/single_season_std_by_role/{season}")
async def single_season_std_by_role(season: str):
return Response(
content=json.dumps(std_dev_data()[season]), media_type="application/json"
)


@app.get("/d/all_seasons_std_by_role")
async def all_seasons_std_by_role():
return Response(
content=json.dumps(std_dev_data_flatten(std_dev_data())), media_type="application/json"
)


@app.get("/chart/{season}")
async def chart_data(season: str):
return Response(
Expand Down

0 comments on commit a7674e2

Please sign in to comment.