Skip to content
Snippets Groups Projects
Commit ef4e82ae authored by Remco Tukker's avatar Remco Tukker
Browse files

add a nren selection page in the frontend to be able to evaluate the conversion results

parent 3b8d694c
No related branches found
No related tags found
1 merge request!47Feature/comp 218 migrating 2022 data
......@@ -30,19 +30,30 @@ SELECT question_id, value
FROM answers a
WHERE nren_id = {}
AND value NOT IN ('""', '[]', '"NA"', '"N/A"', '[""]', '["-"]', '["/"]')
AND NOT EXISTS (SELECT 1 FROM answers a2 WHERE a.question_id = a2.question_id AND a.nren_id = a2.nren_id AND a2.id > a.id)
AND question_id IN (16402,16405,16406,16407,16408,16409,16410,16413,16414,16416,16417,16418,16419,16420,16422,16426,16429,16430,16432,16433,16434,16435,16438,16439,16446,16448,16449,
16450,16451,16452,16453,16455,16456,16457,16458,16459,16460,16461,16462,16463,16464,16465,16468,16469,16470,16471,16472,16473,16474,16475,16476,16477,16478,16479,
16480,16481,16482,16483,16484,16485,16486,16488,16489,16490,16491,16492,16493,16494,16495,16496,16497,16499,16500,16501,16502,16503,16504,16760,16761,16762,16763,
16507,16509,16510,16511,16512,16513,16514,16515,16516,16517,16518,16519,16520,16521,16522,16523,16524,16525,16526,16527,16528,16529,16530,16531,16532,16533,16534,
16535,16536,16537,16538,16539,16540,16541,16542,16543,16544,16545,16546,16547,16548,16550,16551,16552,16553,16554,16555,16556,16557,16558,16559,16560,16561,16562,
16563,16564,16565,16566,16567,16568,16569,16570,16571,16572,16573,16574,16575,16576,16577,16578,16579,16581,16582,16583,16584,16585,16586,16587,16588,16589,16590,
16592,16593,16594,16595,16596,16597,16598,16599,16600,16601,16602,16603,16604,16605,16606,16607,16608,16609,16610,16611,16613,16614,16615,16616,16617,16618,16619,
16620,16621,16622,16623,16624,16625,16626,16627,16628,16629,16630,16631,16632,16634,16635,16636,16637,16638,16639,16640,16641,16642,16643,16646,16647,16648,16649,
16650,16652,16653,16654,16656,16658,16659,16662,16663,16664,16665,16666,16667,16668,16669,16670,16672,16673,16674,16675,16676,16677,16678,16679,16680,16681,16682,
16683,16684,16685,16687,16688,16689,16691,16692,16694,16695,16696,16697,16698,16699,16700,16701,16702,16703,16704,16705,16706,16707,16708,16709,16710,16711,16712,
16713,16714,16715,16716,16717,16718,16719,16720,16721,16722,16723,16724,16725,16726,16727,16728,16729,16730,16731,16732,16733,16734,16735,16736,16737,16738,16739,
16740,16741,16742,16743,16744,16746,16747,16748,16749,16750,16752,16753,16754,16755,16756,16757,16758);
AND NOT EXISTS (
SELECT 1 FROM answers a2 WHERE a.question_id = a2.question_id AND a.nren_id = a2.nren_id AND a2.id > a.id
)
AND question_id IN (16402,16405,16406,16407,16408,16409,16410,16413,16414,16416,16417,16418,16419,16420,16422,
16426,16429,16430,16432,16433,16434,16435,16438,16439,16446,16448,16449,16450,16451,16452,
16453,16455,16456,16457,16458,16459,16460,16461,16462,16463,16464,16465,16468,16469,16470,
16471,16472,16473,16474,16475,16476,16477,16478,16479,16480,16481,16482,16483,16484,16485,
16486,16488,16489,16490,16491,16492,16493,16494,16495,16496,16497,16499,16500,16501,16502,
16503,16504,16760,16761,16762,16763,16507,16509,16510,16511,16512,16513,16514,16515,16516,
16517,16518,16519,16520,16521,16522,16523,16524,16525,16526,16527,16528,16529,16530,16531,
16532,16533,16534,16535,16536,16537,16538,16539,16540,16541,16542,16543,16544,16545,16546,
16547,16548,16550,16551,16552,16553,16554,16555,16556,16557,16558,16559,16560,16561,16562,
16563,16564,16565,16566,16567,16568,16569,16570,16571,16572,16573,16574,16575,16576,16577,
16578,16579,16581,16582,16583,16584,16585,16586,16587,16588,16589,16590,16592,16593,16594,
16595,16596,16597,16598,16599,16600,16601,16602,16603,16604,16605,16606,16607,16608,16609,
16610,16611,16613,16614,16615,16616,16617,16618,16619,16620,16621,16622,16623,16624,16625,
16626,16627,16628,16629,16630,16631,16632,16634,16635,16636,16637,16638,16639,16640,16641,
16642,16643,16646,16647,16648,16649,16650,16652,16653,16654,16656,16658,16659,16662,16663,
16664,16665,16666,16667,16668,16669,16670,16672,16673,16674,16675,16676,16677,16678,16679,
16680,16681,16682,16683,16684,16685,16687,16688,16689,16691,16692,16694,16695,16696,16697,
16698,16699,16700,16701,16702,16703,16704,16705,16706,16707,16708,16709,16710,16711,16712,
16713,16714,16715,16716,16717,16718,16719,16720,16721,16722,16723,16724,16725,16726,16727,
16728,16729,16730,16731,16732,16733,16734,16735,16736,16737,16738,16739,16740,16741,16742,
16743,16744,16746,16747,16748,16749,16750,16752,16753,16754,16755,16756,16757,16758);
"""
NREN_IDS = {
......@@ -92,7 +103,6 @@ NREN_IDS = {
}
def query_nren(nren_id: int):
query = ANSWERS_2022_QUERY.format(nren_id)
answers = {}
......
......@@ -27,13 +27,24 @@ class VerificationStatus(str, Enum):
Edited = "edited" # a question for which last years answer was edited
@routes.route('/open', methods=['GET'])
@routes.route('/nrens', methods=['GET'])
@common.require_accepts_json
def open_survey() -> Any:
def get_nrens() -> Any:
entries = [
{"id": entry.id, "name": entry.name}
for entry in db.session.scalars(select(NREN).order_by(NREN.name))
]
return jsonify(entries)
@routes.route('/open/<string:nren_name>', methods=['GET'])
@common.require_accepts_json
def open_survey(nren_name) -> Any:
# just a hardcoded year and nren for development for now
nren = db.session.execute(select(NREN).order_by(NREN.id).limit(1)).scalar_one()
nren = db.session.execute(select(NREN).filter(NREN.name == nren_name)).scalar_one()
year = 1989
last_year = 2022
survey = db.session.scalar(select(Survey).where(Survey.year == year))
if survey is None or survey.survey == {}:
......@@ -43,17 +54,18 @@ def open_survey() -> Any:
with p.open('r') as f:
survey = json.load(f)
# TODO add some magic strings in the json (like the year, url validation regex, maybe countries list) and interpolate them here
# TODO add some magic strings in the json (like the year, url validation regex, maybe countries list)
# and interpolate them here
data: Optional[dict] = None
page = 0
verification_status: dict[str, str] = {"budget": VerificationStatus.Unverified, "TODO": "remove or set everything to new"}
verification_status: dict[str, str] = {"budget": VerificationStatus.Unverified, "TODO": "remove or set all to new"}
response = db.session.scalar(
select(SurveyResponse).where(SurveyResponse.survey_year == year).where(SurveyResponse.nren_id == nren.id)
)
previous_response = db.session.scalar(
select(SurveyResponse).where(SurveyResponse.survey_year == year - 1).where(SurveyResponse.nren_id == nren.id)
select(SurveyResponse).where(SurveyResponse.survey_year == last_year).where(SurveyResponse.nren_id == nren.id)
)
if response:
......
......@@ -17,7 +17,7 @@ enum VerificationStatus {
}
function SurveyComponent() {
function SurveyComponent({ nrenName }) {
const [surveyModel, setSurveyModel] = useState<Model>();
const verificationStatus = useRef<Map<string, VerificationStatus>>(new Map());
......@@ -58,7 +58,7 @@ function SurveyComponent() {
async function getModel()
{
const response = await fetch('/api/survey/open');
const response = await fetch('/api/survey/open/' + nrenName);
const json = await response.json();
for (const questionName in json["verification_status"]) {
......
import React, { useState, useEffect } from "react";
import SurveyComponent from "./SurveyComponent";
interface Nren {
id: number
name: string
}
function SurveySelectionComponent() {
const [nrens, setNrens] = useState<Nren[]>([]);
const [selectedNren, setSelectedNren] = useState<Nren | null>(null);
useEffect(() => {
// Fetch organizations from the API
fetchNrens();
}, []);
const fetchNrens = async () => {
try {
const response = await fetch('/api/survey/nrens');
const data = await response.json();
setNrens(data);
} catch (error) {
console.error('Error fetching organizations:', error);
}
};
const handleNrenSelect = (nren) => {
setSelectedNren(nren);
};
if (!selectedNren) {
return (
<div>
<h2>Select an organization:</h2>
<ul>
{nrens.map((nren) => (
<li key={nren.id} onClick={() => handleNrenSelect(nren)}>
{nren.name}
</li>
))}
</ul>
</div>
);
}
return <SurveyComponent nrenName={selectedNren.name} />;
}
export default SurveySelectionComponent;
\ No newline at end of file
import React from 'react';
import { createRoot } from 'react-dom/client';
import SurveyComponent from './SurveyComponent';
import SurveySelectionComponent from './SurveySelectionComponent';
const container = document.getElementById('root') as HTMLElement;
......@@ -10,6 +10,6 @@ const root = createRoot(container);
root.render(
<React.StrictMode>
<SurveyComponent />
<SurveySelectionComponent />
</React.StrictMode>
)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment