Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6730 from kaizumaki/feature/issue-6729-add-chart-…
Browse files Browse the repository at this point in the history
…over65

「報告日別による陽性者数(65歳以上)の推移」グラフカードを実装
  • Loading branch information
nyagihime committed Sep 10, 2021
2 parents 711c5b9 + bc61553 commit 4d96787
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components/index/CardsReference.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const ConfirmedCasesByMunicipalitiesCard = () =>
import(
'@/components/index/CardsReference/ConfirmedCasesByMunicipalities/Card.vue'
)
// 報告日別による陽性者数(65歳以上)の推移
const PositiveNumberOver65Card = () =>
import('@/components/index/CardsReference/PositiveNumberOver65/Card.vue')
// 発症日別による陽性者数の推移
const PositiveNumberByDevelopedDateCard = () =>
import(
Expand Down Expand Up @@ -56,6 +59,7 @@ export default Vue.extend({
return {
rows: [
[ConfirmedCasesAttributesCard, ConfirmedCasesByMunicipalitiesCard],
[PositiveNumberOver65Card],
[PositiveNumberByDevelopedDateCard, PositiveNumberByDiagnosedDateCard],
[DeathsByDeathDateCard, VariantCard],
[MetroCard, AgencyCard],
Expand Down
78 changes: 78 additions & 0 deletions components/index/CardsReference/PositiveNumberOver65/Card.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<template>
<v-col cols="12" md="6" class="DataCard PositiveNumberOver65Card">
<client-only>
<time-bar-chart
:title="$t('報告日別による陽性者数(65歳以上)の推移')"
:title-id="'positive-number-over65'"
:chart-id="'positive-number-over65'"
:chart-data="positiveOver65Data"
:date="date"
:by-date="true"
:unit="$t('')"
>
<template #additionalDescription>
<span>{{ $t('(注)') }}</span>
<ul>
<li>
{{ $t('保健所から発生届が提出された日を基準とする') }}
</li>
<li>
{{ $t('医療機関等が行った検査も含む') }}
</li>
<li>
{{ $t('チャーター機帰国者、クルーズ船乗客等は含まれていない') }}
</li>
</ul>
</template>
</time-bar-chart>
</client-only>
</v-col>
</template>

<script lang="ts">
import Vue from 'vue'
import TimeBarChart from '@/components/index/_shared/TimeBarChart.vue'
import {
Datum as IDatum,
PositiveOver65 as IPositiveOver65,
} from '@/libraries/auto_generated/data_converter/convertPositiveOver65'
import { convertDateToISO8601Format } from '@/utils/formatDate'
import formatGraph, { GraphDataType } from '@/utils/formatGraph'
type Data = {}
type Methods = {}
type Computed = {
date: string
positiveOver65Data: GraphDataType[]
positiveOver65: IPositiveOver65
}
type Props = {}
type DataType = {
日付: string
小計: number
}
export default Vue.extend<Data, Methods, Computed, Props>({
components: {
TimeBarChart,
},
computed: {
date() {
return this.positiveOver65.date
},
positiveOver65Data() {
const data: DataType[] = this.positiveOver65.data.map((d: IDatum) => {
return {
日付: convertDateToISO8601Format(d.date),
小計: d.count,
}
})
return formatGraph(data)
},
positiveOver65() {
return this.$store.state.positiveOver65
},
},
})
</script>
173 changes: 173 additions & 0 deletions libraries/auto_generated/data_converter/convertPositiveOver65.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// To parse this data:
//
// import { Convert, PositiveOver65 } from "./file";
//
// const positiveOver65 = Convert.toPositiveOver65(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.

export interface PositiveOver65 {
date: string;
data: Datum[];
}

export interface Datum {
date: Date;
count: number;
}

// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toPositiveOver65(json: string): PositiveOver65 {
return cast(JSON.parse(json), r("PositiveOver65"));
}

public static positiveOver65ToJson(value: PositiveOver65): string {
return JSON.stringify(uncast(value, r("PositiveOver65")), null, 2);
}
}

function invalidValue(typ: any, val: any, key: any = ''): never {
if (key) {
throw Error(`Invalid value for key "${key}". Expected type ${JSON.stringify(typ)} but got ${JSON.stringify(val)}`);
}
throw Error(`Invalid value ${JSON.stringify(val)} for type ${JSON.stringify(typ)}`, );
}

function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}

function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}

function transform(val: any, typ: any, getProps: any, key: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key);
}

function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val);
}

function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases, val);
}

function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue("array", val);
return val.map(el => transform(el, typ, getProps));
}

function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue("Date", val);
}
return d;
}

function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue("object", val);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, prop.key);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key);
}
});
return result;
}

if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val);
}
if (typ === false) return invalidValue(typ, val);
while (typeof typ === "object" && typ.ref !== undefined) {
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}

function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}

function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}

function a(typ: any) {
return { arrayItems: typ };
}

function u(...typs: any[]) {
return { unionMembers: typs };
}

function o(props: any[], additional: any) {
return { props, additional };
}

function m(additional: any) {
return { props: [], additional };
}

function r(name: string) {
return { ref: name };
}

const typeMap: any = {
"PositiveOver65": o([
{ json: "date", js: "date", typ: "" },
{ json: "data", js: "data", typ: a(r("Datum")) },
], false),
"Datum": o([
{ json: "date", js: "date", typ: Date },
{ json: "count", js: "count", typ: 0 },
], false),
};
27 changes: 27 additions & 0 deletions libraries/repositories/PositiveOver65Repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// eslint-disable-next-line import/no-named-default
import { default as rawData } from '@/data/positive_over65.json'
import {
Convert,
PositiveOver65,
} from '@/libraries/auto_generated/data_converter/convertPositiveOver65'
import {
BaseRepository,
IBaseRepository,
} from '@/libraries/repositories/BaseRepository'

export interface IPositiveOver65Repository
extends IBaseRepository<PositiveOver65> {}

export class PositiveOver65Repository
extends BaseRepository<PositiveOver65>
implements IPositiveOver65Repository
{
/**
* 使用箇所
*
* 報告日別による陽性者数(65歳以上)の推移 (components/index/CardsReference/PositiveNumberOver65/Card.vue)
*/
constructor() {
super(Convert.toPositiveOver65(JSON.stringify(rawData)))
}
}
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ const config: NuxtConfig = {
'/cards/deaths-by-death-date',
'/cards/variant',
'/cards/vaccination',
'/cards/positive-number-over65',
]
const localizedPages = locales
.map((locale) => pages.map((page) => `/${locale}${page}`))
Expand Down
8 changes: 8 additions & 0 deletions pages/cards/_card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import MonitoringConsultationDeskReportsNumberCard from '@/components/index/Card
import PositiveNumberByDevelopedDateCard from '@/components/index/CardsReference/PositiveNumberByDevelopedDate/Card.vue'
// 確定日別による陽性者数の推移
import PositiveNumberByDiagnosedDateCard from '@/components/index/CardsReference/PositiveNumberByDiagnosedDate/Card.vue'
// 報告日別による陽性者数(65歳以上)の推移
import PositiveNumberOver65Card from '@/components/index/CardsReference/PositiveNumberOver65/Card.vue'
// L452R変異株スクリーニングの実施状況
import VariantCard from '@/components/index/CardsReference/Variant/Card.vue'
import { convertDateToSimpleFormat } from '@/utils/formatDate'
Expand Down Expand Up @@ -95,6 +97,7 @@ import { getLinksLanguageAlternative } from '@/utils/i18nUtils'
// ---- その他 参考指標
ConfirmedCasesAttributesCard,
ConfirmedCasesByMunicipalitiesCard,
PositiveNumberOver65Card,
PositiveNumberByDevelopedDateCard,
PositiveNumberByDiagnosedDateCard,
DeathsByDeathDateCard,
Expand Down Expand Up @@ -203,6 +206,11 @@ export default class CardContainer extends Vue implements NuxtConfig {
cardCategory = 'reference'
break
// 発症日別による陽性者数の推移
case 'positive-number-over65':
cardComponent = 'positive-number-over65'
cardCategory = 'reference'
break
// 発症日別による陽性者数の推移
case 'positive-number-by-developed-date':
cardComponent = 'positive-number-by-developed-date-card'
cardCategory = 'reference'
Expand Down
2 changes: 2 additions & 0 deletions store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { InfectionMedicalcareprovisionStatusRepository as InfectionMedicalCarePr
import { MetroRepository } from '@/libraries/repositories/MetroRepository'
import { MonitoringCommentImageRepository } from '@/libraries/repositories/MonitoringCommentImageRepository'
import { NewsRepository } from '@/libraries/repositories/NewsRepository'
import { PositiveOver65Repository } from '@/libraries/repositories/PositiveOver65Repository'
import { StayingPopulationRepository } from '@/libraries/repositories/StayingPopulationRepository'
import { TokyoRuleRepository } from '@/libraries/repositories/TokyoRuleRepository'
import { VaccinationRepository } from '@/libraries/repositories/VaccinationRepository'
Expand All @@ -28,4 +29,5 @@ export const state = () => ({
tokyoRule: new TokyoRuleRepository().data,
vaccination: new VaccinationRepository().data,
variants: new VariantsRepository().data,
positiveOver65: new PositiveOver65Repository().data,
})
1 change: 1 addition & 0 deletions ui-test/ogp_screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"/cards/deaths-by-death-date": (959, 570),
"/cards/variant": (959, 730),
"/cards/vaccination": (959, 730),
"/cards/positive-number-over65": (959, 500),
}

options = webdriver.ChromeOptions()
Expand Down

0 comments on commit 4d96787

Please sign in to comment.