Skip to content

Commit

Permalink
Merge pull request #150 from fhstp/new_csv_export
Browse files Browse the repository at this point in the history
New csv export
  • Loading branch information
alex-rind authored Aug 28, 2024
2 parents b49beae + c69db44 commit 55fd7a4
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 115 deletions.
11 changes: 3 additions & 8 deletions src/components/SideMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,13 @@ export default defineComponent({
);
},
exportCSV: () => {
const today = new Date();
downloadText(
store.state.nwk.ego.name +
" " +
visibleNWKVersion.value?.title +
" " +
visibleNWKVersion.value?.date?.substring(8, 10) +
"." +
visibleNWKVersion.value?.date?.substring(5, 7) +
"." +
visibleNWKVersion.value?.date?.substring(0, 4) +
today.toLocaleDateString("en-CA") +
".csv",
statisticsCSV(store.state.nwk, store.getters["displayName"])
statisticsCSV(store.state.record.versions)
);
},
Expand Down
224 changes: 117 additions & 107 deletions src/data/statisticsCSV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,127 +5,137 @@ import {
import {
analyseNWKbyCategory,
calculateDensity,
getOrInit,
NetworkAnalysis,
} from "@/data/NetworkAnalysis";
import { NWK } from "@/data/NWK";
import { Alter } from "./Alter";
import { store } from "@/store";
import { NWKVersion } from "./NWKVersion";

const SEP = ";";
let output = "";

export function statisticsCSV(
nwk: NWK,
displayName: (a: Alter) => string
versions: NWKVersion[]
): string {
let output = "Auswertung" + SEP + nwk.ego.name;
output = "";

output += "Name des Egos" + SEP;
output += "Name der Netzwerkkarte" + SEP;
output += "Datum" + SEP;
output += "ID" + SEP;
output += "Netzwerksektor" + SEP;
output += "Netzwerkgröße" + SEP;
output += "Netzwerkgröße (+aktivierbare)" + SEP;
output += "nach Geschlecht weiblich" + SEP;
output += "nach Geschlecht weiblich (+aktivierbare)" + SEP;
output += "nach Geschlecht männlich" + SEP;
output += "nach Geschlecht männlich (+aktivierbare)" + SEP;
output += "nach Geschlecht divers" + SEP;
output += "nach Geschlecht divers (+aktivierbare)" + SEP;
output += "nach Geschlecht nicht festgelegt" + SEP;
output += "nach Geschlecht nicht festgelegt (+aktivierbare)" + SEP;
output += "nach Horizont nah" + SEP;
output += "nach Horizont nah (+aktivierbare)" + SEP;
output += "nach Horizont mittel" + SEP;
output += "nach Horizont mittel (+aktivierbare)" + SEP;
output += "nach Horizont entfernt" + SEP;
output += "nach Horizont entfernt (+aktivierbare)" + SEP;
output += "Durschschn. Nähe" + SEP;
output += "Durschschn. Nähe (SD)" + SEP;
output += "Dichte" + SEP;
output += "Durchschn. Degree" + SEP;
output += "Durchschn. Degree (SD)" + SEP;
output += "Star(s)" + SEP;
output += "Isolierte" + SEP;
output += "Personen ohne Kante zum Ego" + SEP;
output += "\n";

for (const cat of allAlterCategorizationKeys) {
// loop each tab of the statistics panel (below each other on single sheet)
const categorization = getAlterCategorization(cat);
const networkAnalysis = analyseNWKbyCategory(nwk, categorization);

output += "\n\n" + categorization.label + "\n\n";

output += "Kennzahl";
for (const label of categorization.categories) {
output += SEP + label;
}

output += "\nNetzwerkgröße";
for (const label of categorization.categories) {
output +=
SEP + getOrInit(networkAnalysis, label).alterConnected.toFixed(0);
}

output += "\nBeziehungsgewicht";
for (const label of categorization.categories) {
// TODO change to naehenAvg and naehenDev
// output += SEP + getOrInit(networkAnalysis, label).naehenSum.toFixed(0);
}

output += "\nDichte der Kategorie";
for (const label of categorization.categories) {
const { alterConnectable, intConnCount } = getOrInit(
networkAnalysis,
label
);
output +=
SEP +
calculateDensity(alterConnectable, intConnCount).toLocaleString(
undefined,
{
minimumFractionDigits: 3,
maximumFractionDigits: 3,
for (const version of versions) {
for (const cat of allAlterCategorizationKeys) {
const categorization = getAlterCategorization(cat);
const networkAnalysisMap = analyseNWKbyCategory(version.nwk, categorization);

for (const label of categorization.categories) {
const networkAnalysis = networkAnalysisMap.get(label);
if (networkAnalysis) {
getDataForKeyFigures(networkAnalysis, version.nwk.ego.name, version.title, version.date, version.id, categorization.label, label);
}
);
}

output += "\nStar(s)";
output += categorization.categories
.map((label) => {
const { stars, maxDegree } = getOrInit(networkAnalysis, label);
if (stars.length > 0 && maxDegree > 0) {
return stars.map((a) => displayName(a)).join(", ");
// + " (" + maxDegree + " Beziehungen)"
} else {
return "-";
output += "\n";
}
})
.reduce((prev, curr) => prev + SEP + curr, "");

/* bridges were removed from simple statistics
output += "\nBrücken";
for (const label of categorization.categories) {
output +=
SEP + getOrInit(networkAnalysis, label).bridges.length.toFixed(0);
}
output += "\nBrückenperson(en)";
output += makeComputedAlterGroup(
networkAnalysis,
categorization.categories,
displayName,
"bridgePersons"
).reduce((prev, curr) => prev + SEP + curr, "");
*/

output += "\nIsolierte";
output += makeComputedAlterGroup(
networkAnalysis,
categorization.categories,
displayName,
"isolated"
).reduce((prev, curr) => prev + SEP + curr, "");
}
}

output += "\n";
return output;
}

output += "\nPersonen ohne Kante zur Ankerperson";
output += makeComputedAlterGroup(
networkAnalysis,
categorization.categories,
displayName,
"alterZeroEdge"
).reduce((prev, curr) => prev + SEP + curr, "");
function getDataForKeyFigures(networkAnalysis: NetworkAnalysis, ego: string, title: string, date: string, id: number, categoryLabel: string, label: string) {
output += ego + SEP;
output += title + SEP;
output += date + SEP;
output += id + SEP;
output += categoryLabel + (label ? " " + label : "") + SEP;
output += networkAnalysis.alterConnectable + SEP;
output += networkAnalysis.alterConnected + SEP;

for (const [i, g] of networkAnalysis.genderConnected.entries()) {
output += g + SEP;
output += networkAnalysis.genderConnectable[i] + SEP;
}
for (const [i, g] of networkAnalysis.horizonConnected.entries()) {
output += g + SEP;
output += networkAnalysis.horizonConnectable[i] + SEP;
}
output += networkAnalysis.naehenAvg.toString().replace('.', ',') + SEP;
output += networkAnalysis.naehenDev.toString().replace('.', ',') + SEP;
const density = calculateDensity(networkAnalysis.alterConnectable, networkAnalysis.intConnCount);
output += density.toString().replace('.', ',') + SEP;
output += networkAnalysis.degreeAvg.toString().replace(".", ",") + SEP;
output += networkAnalysis.degreeDev.toString().replace('.', ',') + SEP;
output += formatStars(networkAnalysis) + SEP;
output += formatIsolated(networkAnalysis.isolated) + SEP;
output += formatZeroEdge(networkAnalysis.alterZeroEdge) + SEP;
}

return output;
function formatStars(networkAnalysis: NetworkAnalysis): string {
const alteri = networkAnalysis.stars;
if (alteri.length > 0 && networkAnalysis.maxDegree > 0) {
return document.documentElement.lang == "de"
? alteri.map((a) => store.getters["displayName"](a)).join(", ") +
" (" +
networkAnalysis.maxDegree +
" Beziehungen)"
: alteri.map((a) => store.getters["displayName"](a)).join(", ") +
" (" +
networkAnalysis.maxDegree +
" relations)";
} else {
return document.documentElement.lang == "de" ? "keine" : "none";
}
}

function makeComputedAlterGroup(
networkAnalysis: Map<string, NetworkAnalysis>,
categoryLabels: string[],
displayName: (a: Alter) => string,
group: "stars" | "isolated" | "alterZeroEdge"
) {
return categoryLabels.map((cat) => {
const analysis = getOrInit(networkAnalysis, cat);
if (analysis[group].length > 0) {
return (
analysis[group].length +
" (" +
analysis[group].map((a) => displayName(a)).join(", ") +
")"
);
} else {
return "0";
}
});
function formatIsolated(alteri: Alter[]): string {
if (alteri.length > 0) {
return (
alteri.length +
" (" +
alteri.map((a) => store.getters["displayName"](a)).join(", ") +
")"
);
} else {
return "0";
}
}

function formatZeroEdge(alteri: Alter[]): string {
if (alteri.length > 0) {
return (
alteri.length +
" (" +
alteri.map((a) => store.getters["displayName"](a)).join(", ") +
")"
);
} else {
return "0";
}
}

0 comments on commit 55fd7a4

Please sign in to comment.