Visual apperance
This commit is contained in:
@@ -1,11 +1,59 @@
|
||||
import * as d3 from "d3";
|
||||
|
||||
export interface ResponseData {
|
||||
id: number;
|
||||
question: string;
|
||||
response: string;
|
||||
function mapSkillToNumber(skill: string): number {
|
||||
const skills: { [key: string]: number } = {
|
||||
"Gar nicht qualifiziert": 0,
|
||||
"Leicht qualifiziert": 1,
|
||||
"Mäßig qualifiziert": 2,
|
||||
"Sehr qualifiziert": 3,
|
||||
"Äußerst qualifiziert": 4,
|
||||
};
|
||||
return skills[skill] !== undefined ? skills[skill] : -1;
|
||||
}
|
||||
|
||||
export function parseCSV(csv: string): d3.DSVRowArray<string> {
|
||||
return d3.csvParse(csv);
|
||||
const sheet_id = "12pGfvJx0SQmb6mnnVygmZsEeLZ6bFrpZvq8GYw2oX9E";
|
||||
const sheet_name = "Responses";
|
||||
const url = `https://docs.google.com/spreadsheets/d/${sheet_id}/gviz/tq?tqx=out:csv&sheet=${sheet_name}`;
|
||||
|
||||
export interface ResponseData {
|
||||
timestamp: number;
|
||||
position: string;
|
||||
question: string;
|
||||
response: number;
|
||||
}
|
||||
|
||||
export function parseCSV(csv: string): ResponseData[] {
|
||||
const rowConverter = (row: d3.DSVRowString): ResponseData[] => {
|
||||
const responses: { [key: string]: number } = {};
|
||||
Object.keys(row).forEach((key) => {
|
||||
// Likert scale responses have their group name in square brackets at the end of the column name
|
||||
const m = key.match(/\[([^\]]+)\]$/);
|
||||
if (m) {
|
||||
const category = m[1];
|
||||
responses[category] = mapSkillToNumber(row[key]);
|
||||
}
|
||||
});
|
||||
return Object.entries(responses).flatMap(([category, response]) => ({
|
||||
timestamp: new Date(row["Timestamp"]).getTime(),
|
||||
position: row["Position"],
|
||||
question: category,
|
||||
response: response,
|
||||
}));
|
||||
};
|
||||
const rows = d3.csvParse(csv, rowConverter);
|
||||
console.log("Parsed rows:", rows);
|
||||
return rows.flatMap((row) => row);
|
||||
}
|
||||
|
||||
export function fetchGoogleSheet() {
|
||||
return fetch(url)
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then((csv) => {
|
||||
return parseCSV(csv);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user