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

統計画面を実装 / Show statistics #3

Merged
merged 36 commits into from
May 31, 2022
Merged

統計画面を実装 / Show statistics #3

merged 36 commits into from
May 31, 2022

Conversation

nafuka11
Copy link
Owner

@nafuka11 nafuka11 commented May 19, 2022

Fix #1

変更内容

./cursus_users.json を読み込み、 /stats で統計画面を表示します。

動作確認方法

  1. /v2/cursus_users を叩いて得たjsonを cursus_users.json として保存します。
  2. 必要なパッケージをインストールします。
    yarn
    
  3. developmentサーバを起動します。
    yarn dev
    

@nafuka11 nafuka11 added the enhancement New feature or request label May 19, 2022
@nafuka11 nafuka11 self-assigned this May 19, 2022
@nafuka11
Copy link
Owner Author

グラフを表示するためのデータ構造

現在のデータ構造

beginAtList:入学日(string)のリスト

["2022-01-01", "2022-01-02"]

studentStatus:keyが入学日でvalueが在籍/BH/入学予定人数なオブジェクト

{
  "2022-01-01": {
    current: 1,
    blackholed: 2,
    future: 3,
  },
  "2022-01-02": {
    current: 2,
    blackholed: 3,
    future: 4
  }
}

evaluationPoint:evaluationPointの合計(number)

42

levelBeginAtCurrent:入学日keyでvalueがlevel/countのオブジェクトの配列、なオブジェクトの在籍学生版
levelBeginAtAll:↑の全学生版

{
  "2022-01-01": [{
    level: 0,
    count: 1
  },{
    level: 1,
    count: 2
  }]},
  "2022-01-02": [{
    level: 1,
    count: 2
  }]
}

levelStudents:{level: 学生数}なオブジェクト

{1: 2, 2: 3}

問題点

集計を各データごとに行っていて、どこかでミスしていても気づきにくい

改善案

BeginAtLevelTableで行っている集計処理を使う。

const calcTableData = () => {
const tableData = Object.keys(levelBeginAt).map((key) => {
const counts = [...Array(maxLevel + 1)].map(
(_, lv) => levelBeginAt[key].find((v) => v.level === lv)?.count ?? 0
);
const sum = counts.reduce((prev, cur) => prev + cur);
return [...counts, sum];
});
const lastRow = [...Array(maxLevel + 1)].map((_, lv) =>
tableData.reduce((sum, cur) => sum + cur[lv], 0)
);
lastRow.push(lastRow.reduce((prev, cur) => prev + cur));
tableData.push(lastRow);
return tableData;

入学日の文字列配列はそのままに、入学日・レベルに対応する学生数を二重配列なテーブル形式でデータを持たせる。

入学日が以下で、

["2022-01-01", "2022-01-02"]

テーブル形式のデータが以下の場合、

[[1, 2, 3, 6],
 [2, 3, 4, 9],
 [3, 5, 7, 15]]
begin_at Lv.0 Lv.1 Lv.2 Sum
2022-01-01 1 2 3 6
2022-01-02 2 3 4 9
Sum 3 5 7 15

と考える。

こうすると、未来に入学する学生数(future)は、begin_atが未来の日付である学生数のSumから分かる。

@nafuka11
Copy link
Owner Author

上記コメントの問題は別Issueで対処します。

@nafuka11 nafuka11 merged commit cb29992 into main May 31, 2022
@nafuka11 nafuka11 deleted the 1-show-stats branch May 31, 2022 05:28
@nafuka11 nafuka11 changed the title 統計画面を実装 統計画面を実装 / Show statistics Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cursus_usersのjsonを元に統計画面を表示する
1 participant