/*####################################################################### # RDOS operating system # Copyright (C) 1988-2003, Leif Ekblad # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. The only exception to this rule # is for commercial usage in embedded systems. For information on # usage in commercial embedded systems, contact embedded@rdos.net # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # The author of this program may be contacted at leif@rdos.net # # conv8.cpp # Convert exported quiz-8 to binary file # ########################################################################*/ #include #include #include #include #include "pop.h" #include "file.h" #include "quizdb8.h" #include "conv8.h" #define FALSE 0 #define TRUE !FALSE #define MAX_IN_ROW 0x8000 void OpenPca(const char *Suffix); void AddPca(int Gender, int BirthYear, int ScoreDiff, char *ScoreArr, int Count); void ClosePca(); static TFile *quizfile; /*################## HandleRow ########################## * Purpose....: Handle a row # * In params..: * # * Out params.: * # * Returns....: * # * Created....: 96-11-20 le # *##########################################################################*/ static void HandleRow(TQuizRow *Row) { quizfile->Write(Row, sizeof(TQuizRow)); printf("8: %d AS: %d, NT: %d\r\n", Row->ID, Row->AsResult, Row->NtResult); } /*################## UpdateScore ########################## * Purpose....: Calculate & update a modified score based on current quiz-weights # * In params..: * # * Out params.: * # * Returns....: * # * Created....: 96-11-20 le # *##########################################################################*/ static void UpdateScore(TQuizRow *row) { int grp; int dx; int i; int val; int w; int sum; int totsum; for (grp = 0; grp < 14; grp++) { sum = 0; totsum = 0; for (i = 0; i < 150; i++) { val = row->Quiz[i]; if (val) { w = Gw[i][grp]; if (w < 0) { w = -w; val = 3 - val; } else val--; sum += val * w; totsum += 2 * w; } } if (totsum) row->GroupResult[grp] = 100 * sum / totsum; else row->GroupResult[grp] = 0; } } /*################## ProcessRow ########################## * Purpose....: Process row # * In params..: * # * Out params.: * # * Returns....: * # * Created....: 96-11-20 le # *##########################################################################*/ static void ProcessRow(char *str) { char *valstr; char *ptr; int fieldno; int i; int j; int year, month, day; int hour, min, sec; TDateTime *time; TQuizRow Row; ptr = str; for (fieldno = 0; ptr; fieldno++) { valstr = str; ptr = strstr(str, ";"); if (ptr) *ptr = 0; str = ptr + 1; switch (fieldno) { case 0: Row.ID = atol(valstr); break; case 1: sscanf(valstr+1, "%04d-%02d-%02d %02d:%02d:%02d", &year, &month, &day, &hour, &min, &sec); time = new TDateTime(year, month, day, hour, min, sec); Row.LsbTime = time->GetLsb(); Row.MsbTime = time->GetMsb(); delete time; break; case 2: Row.BirthYear = atoi(valstr); break; case 3: Row.Gender = atoi(valstr); break; case 4: Row.Hair = atoi(valstr); break; case 5: Row.Eye = atoi(valstr); break; case 6: Row.Lang = atoi(valstr); break; case 7: Row.Autism = atoi(valstr); break; case 8: Row.Aspie = atoi(valstr); break; case 9: Row.ADHD = atoi(valstr); break; case 10: Row.HnSimilar = atoi(valstr); break; case 11: Row.HnGender = atoi(valstr); break; case 12: Row.AsResult = atoi(valstr); break; case 13: Row.NtResult = atoi(valstr); break; default: i = fieldno - 14; if (i < 150) Row.Quiz[i] = atoi(valstr); else { i = i - 151; j = i % 3; i = i / 3; if (i < 45) Row.Stim[i][j] = atoi(valstr); } break; } } UpdateScore(&Row); HandleRow(&Row); AddPca(Row.Gender, Row.BirthYear, Row.AsResult - Row.NtResult, &Row.Quiz[0], 150); } /*################## Conv8 ########################## * Purpose....: Convert quiz 8 # * In params..: * # * Out params.: * # * Returns....: * # * Created....: 96-11-20 le # *##########################################################################*/ void Conv8() { char buf[MAX_IN_ROW]; int size; long pos = 0; TFile infile("raw\\aspie-quiz-8.csv"); TFile outfile("bin\\quiz8.bin", 0); char *ptr; quizfile = &outfile; OpenPca("8"); size = infile.Read(buf, MAX_IN_ROW); buf[size] = 0; ptr = strchr(buf, 0xd); if (ptr) *ptr = 0; pos += strlen(buf) + 1; infile.SetPos(pos); while (size = infile.Read(buf, MAX_IN_ROW)) { buf[size] = 0; ptr = strchr(buf, 0xd); if (ptr) *ptr = 0; pos += strlen(buf) + 1; infile.SetPos(pos); if (ptr) ProcessRow(buf); } ClosePca(); }