adding data browser
This commit is contained in:
@@ -8,33 +8,38 @@ import { Milestone } from '../enums/milestone';
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class DataService {
|
||||
private _data: Record<string, any>[] = [];
|
||||
private data = new ReplaySubject<Record<string, any>[]>();
|
||||
readonly Data = this.data.asObservable();
|
||||
private data = new ReplaySubject<Record<string, any>[]>(1);
|
||||
readonly Data$ = this.data.asObservable();
|
||||
readonly Data = () => this._data;
|
||||
|
||||
private _counties = new Map<string, string>();
|
||||
private counties = new ReplaySubject<KeyValue[]>();
|
||||
readonly Counties = this.counties.asObservable();
|
||||
private counties = new ReplaySubject<KeyValue[]>(1);
|
||||
readonly Counties$ = this.counties.asObservable();
|
||||
readonly Counties = () => this._counties;
|
||||
|
||||
private _schools = new Map<string, string>();
|
||||
private schools = new ReplaySubject<KeyValue[]>();
|
||||
readonly Schools = this.schools.asObservable();
|
||||
private schools = new ReplaySubject<KeyValue[]>(1);
|
||||
readonly Schools$ = this.schools.asObservable();
|
||||
readonly Schools = () => this._schools;
|
||||
|
||||
private _years = Array(2023 - 2015 + 1)
|
||||
.fill(0)
|
||||
.map((_, index) => 2015 + index)
|
||||
.filter((y) => y !== 2020);
|
||||
private years = new ReplaySubject<KeyValue[]>();
|
||||
readonly Years = this.years.asObservable();
|
||||
.map((_, index) => 2015 + index);
|
||||
private years = new ReplaySubject<KeyValue[]>(1);
|
||||
readonly Years$ = this.years.asObservable();
|
||||
readonly Years = () => this._years;
|
||||
|
||||
private _grades = Array(8 - 3 + 1)
|
||||
.fill(0)
|
||||
.map((_, index) => 3 + index);
|
||||
private grades = new ReplaySubject<KeyValue[]>();
|
||||
readonly Grades = this.grades.asObservable();
|
||||
private grades = new ReplaySubject<KeyValue[]>(1);
|
||||
readonly Grades$ = this.grades.asObservable();
|
||||
readonly Grades = () => this._grades;
|
||||
|
||||
private _cohorts = new Map<string, string>();
|
||||
private cohorts = new ReplaySubject<KeyValue[]>();
|
||||
readonly Cohorts = this.cohorts.asObservable();
|
||||
private cohorts = new ReplaySubject<KeyValue[]>(1);
|
||||
readonly Cohorts$ = this.cohorts.asObservable();
|
||||
readonly Cohorts = () => this._cohorts;
|
||||
|
||||
constructor() {
|
||||
this.load();
|
||||
@@ -44,7 +49,7 @@ export class DataService {
|
||||
let count = this._years.length * this._grades.length;
|
||||
this._years.forEach((year: number) => {
|
||||
this._grades.forEach((grade: number) => {
|
||||
Papa.parse(`assets/data/${year}-${grade}.csv`, {
|
||||
Papa.parse(`assets/data/${year === 2020 ? 2019 : year}-${grade}.csv`, {
|
||||
download: true,
|
||||
header: false,
|
||||
complete: (results: ParseResult<Record<string, any>>) => {
|
||||
@@ -68,36 +73,37 @@ export class DataService {
|
||||
if (isNaN(code)) return;
|
||||
|
||||
const ms = {} as Record<string, any>;
|
||||
// const ms = new Milestone({});
|
||||
ms[Milestone.Year] = year;
|
||||
ms[Milestone.Grade] = grade;
|
||||
ms[Milestone.Cohort] = cohort;
|
||||
ms[Milestone.County] = fs(Csv.County_Code, record);
|
||||
ms[Milestone.School] = fs(Csv.School_Code, record);
|
||||
ms[Milestone.ELACount] = fn(Csv.ELA_Count, record);
|
||||
ms[Milestone.ELAMean] = fn(Csv.ELA_Mean, record);
|
||||
ms[Milestone.ELA0] = fn(Csv.ELA_L0, record);
|
||||
ms[Milestone.ELA1] = fn(Csv.ELA_L1, record);
|
||||
ms[Milestone.ELA2] = fn(Csv.ELA_L2, record);
|
||||
ms[Milestone.ELA3] = fn(Csv.ELA_L3, record);
|
||||
ms[Milestone.MathCount] = fn(Csv.Math_Count, record);
|
||||
ms[Milestone.MathMean] = fn(Csv.Math_Mean, record);
|
||||
ms[Milestone.Math0] = fn(Csv.Math_L0, record);
|
||||
ms[Milestone.Math1] = fn(Csv.Math_L1, record);
|
||||
ms[Milestone.Math2] = fn(Csv.Math_L2, record);
|
||||
ms[Milestone.Math3] = fn(Csv.Math_L3, record);
|
||||
ms[Milestone.SciCount] = fn(Csv.Science_Count, record);
|
||||
ms[Milestone.SciMean] = fn(Csv.Science_Mean, record);
|
||||
ms[Milestone.Sci0] = fn(Csv.Science_L0, record);
|
||||
ms[Milestone.Sci1] = fn(Csv.Science_L1, record);
|
||||
ms[Milestone.Sci2] = fn(Csv.Science_L2, record);
|
||||
ms[Milestone.Sci3] = fn(Csv.Science_L3, record);
|
||||
ms[Milestone.SocCount] = fn(Csv.Social_Count, record);
|
||||
ms[Milestone.SocMean] = fn(Csv.Social_Mean, record);
|
||||
ms[Milestone.Soc0] = fn(Csv.Social_L0, record);
|
||||
ms[Milestone.Soc1] = fn(Csv.Social_L1, record);
|
||||
ms[Milestone.Soc2] = fn(Csv.Social_L2, record);
|
||||
ms[Milestone.Soc3] = fn(Csv.Social_L3, record);
|
||||
if (year !== 2020) {
|
||||
ms[Milestone.ELACount] = fn(Csv.ELA_Count, record);
|
||||
ms[Milestone.ELAMean] = fn(Csv.ELA_Mean, record);
|
||||
ms[Milestone.ELA0] = fn(Csv.ELA_L0, record);
|
||||
ms[Milestone.ELA1] = fn(Csv.ELA_L1, record);
|
||||
ms[Milestone.ELA2] = fn(Csv.ELA_L2, record);
|
||||
ms[Milestone.ELA3] = fn(Csv.ELA_L3, record);
|
||||
ms[Milestone.MathCount] = fn(Csv.Math_Count, record);
|
||||
ms[Milestone.MathMean] = fn(Csv.Math_Mean, record);
|
||||
ms[Milestone.Math0] = fn(Csv.Math_L0, record);
|
||||
ms[Milestone.Math1] = fn(Csv.Math_L1, record);
|
||||
ms[Milestone.Math2] = fn(Csv.Math_L2, record);
|
||||
ms[Milestone.Math3] = fn(Csv.Math_L3, record);
|
||||
ms[Milestone.SciCount] = fn(Csv.Science_Count, record);
|
||||
ms[Milestone.SciMean] = fn(Csv.Science_Mean, record);
|
||||
ms[Milestone.Sci0] = fn(Csv.Science_L0, record);
|
||||
ms[Milestone.Sci1] = fn(Csv.Science_L1, record);
|
||||
ms[Milestone.Sci2] = fn(Csv.Science_L2, record);
|
||||
ms[Milestone.Sci3] = fn(Csv.Science_L3, record);
|
||||
ms[Milestone.SocCount] = fn(Csv.Social_Count, record);
|
||||
ms[Milestone.SocMean] = fn(Csv.Social_Mean, record);
|
||||
ms[Milestone.Soc0] = fn(Csv.Social_L0, record);
|
||||
ms[Milestone.Soc1] = fn(Csv.Social_L1, record);
|
||||
ms[Milestone.Soc2] = fn(Csv.Social_L2, record);
|
||||
ms[Milestone.Soc3] = fn(Csv.Social_L3, record);
|
||||
}
|
||||
data.push(ms);
|
||||
|
||||
const county = fs(Csv.County_Code, record);
|
||||
@@ -108,21 +114,24 @@ export class DataService {
|
||||
);
|
||||
});
|
||||
|
||||
[
|
||||
{ sort: Milestone.ELAMean, rank: Milestone.ELARank },
|
||||
{ sort: Milestone.MathMean, rank: Milestone.MathRank },
|
||||
{ sort: Milestone.SciMean, rank: Milestone.SciRank },
|
||||
{ sort: Milestone.SocMean, rank: Milestone.SocRank },
|
||||
].forEach((m) => {
|
||||
data
|
||||
.sort(
|
||||
(a: Record<string, any>, b: Record<string, any>) =>
|
||||
+a[m.sort] - b[m.sort]
|
||||
)
|
||||
.forEach(
|
||||
(a: Record<string, any>, index: number) => (a[m.rank] = index)
|
||||
);
|
||||
});
|
||||
if (year !== 2020) {
|
||||
[
|
||||
{ sort: Milestone.ELAMean, rank: Milestone.ELARank },
|
||||
{ sort: Milestone.MathMean, rank: Milestone.MathRank },
|
||||
{ sort: Milestone.SciMean, rank: Milestone.SciRank },
|
||||
{ sort: Milestone.SocMean, rank: Milestone.SocRank },
|
||||
].forEach((m) => {
|
||||
data
|
||||
.sort(
|
||||
(a: Record<string, any>, b: Record<string, any>) =>
|
||||
+a[m.sort] - b[m.sort]
|
||||
)
|
||||
.forEach(
|
||||
(a: Record<string, any>, index: number) =>
|
||||
(a[m.rank] = index)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
this._data.push(...data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user