Skip to content

Commit

Permalink
[#259] Fix rfd serializer and check load value in FE
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Jan 25, 2024
1 parent 5b144bd commit aa8f111
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
22 changes: 11 additions & 11 deletions backend/models/reference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class ReferenceDataDict(TypedDict):
id: int
country: int
commodity: int
region: str
currency: str
year: int
source: str
link: str
region: Optional[str]
currency: Optional[str]
year: Optional[int]
source: Optional[str]
link: Optional[str]
notes: Optional[str]
confidence_level: Optional[str]
range: Optional[str]
Expand All @@ -56,19 +56,19 @@ class ReferenceDataList(TypedDict):
id: int
country: str
commodity: str
source: str
link: str
source: Optional[str]
link: Optional[str]
confidence_level: Optional[str]


class ReferenceValueList(TypedDict):
id: int
source: str
link: str
source: Optional[str]
link: Optional[str]
value: Optional[float]
unit: Optional[str]
region: str
year: int
region: Optional[str]
year: Optional[int]
confidence_level: Optional[str]
type: Optional[str]

Expand Down
2 changes: 2 additions & 0 deletions backend/seeder/reference_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import pandas as pd
import numpy as np
from core.config import generate_config_file
from db.connection import Base, engine, SessionLocal

Expand All @@ -20,6 +21,7 @@ def seeder_reference_data(session: Session):
# reference data
truncatedb(session=session, table="reference_data")
rfd = pd.read_csv(MASTER_DIR + "reference_data.csv")
rfd.replace({np.nan: None}, inplace=True)
for index, row in rfd.iterrows():
country = (
session.query(Country)
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/pages/explore-studies/ExploreStudiesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import ReferenceDataForm from "./ReferenceDataForm";
import { api } from "../../lib";
import { driverOptions } from ".";
import { useParams, useNavigate, useLocation } from "react-router-dom";
import { thousandFormatter } from "../../components/chart/options/common";

const selectProps = {
showSearch: true,
Expand Down Expand Up @@ -299,6 +300,9 @@ const ExploreStudiesPage = () => {
};
const transformData = referenceDataExpand.map((d, di) => {
let value = values[d.key];
if (typeof value === "number") {
value = thousandFormatter(value);
}
if (value && d?.unit) {
value = `${value} ${
values?.[d.unit] ? `(${values[d.unit]})` : "(Unit NA)"
Expand All @@ -312,7 +316,7 @@ const ExploreStudiesPage = () => {
return {
id: di,
label: d.label,
value: value,
value: value || "-",
};
});
setExpandedData(transformData);
Expand Down

0 comments on commit aa8f111

Please # to comment.