/
AdminPrediction.js
1484 lines (1453 loc) · 64 KB
/
AdminPrediction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import React, { Fragment, useCallback, useEffect, useState } from "react";
import { Listbox, Transition } from "@headlessui/react";
import {
ACCENT_BUTTON,
DANGER_BUTTON,
ICON_PLACE_SELF_CENTER,
TEXT_FIELD,
} from "../../assets/styles/styled-components";
import httpClient from "../../http/httpClient";
import { toast } from "react-toastify";
import { importSPKI, jwtVerify } from "jose";
import {
getNameFromString,
getNumberFromString,
MATRIX_RSA_PUBLIC_KEY,
timeFormat,
} from "../../helpers/Helper";
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/react/20/solid";
import {
faCaretLeft,
faCircleMinus,
faFileCsv,
faFlagCheckered,
faMagnifyingGlassChart,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Header, HeaderEmail } from "../../components/headers/Header";
import { useDropzone } from "react-dropzone";
import { LoadingAnimation } from "../../components/loading/LoadingPage";
import { Link } from "react-router-dom";
import DisclosureTogglable from "../../components/disclosure/DisclosureTogglable";
import { getCookie, isAuth, signout } from "../../helpers/Auth";
import Papa from "papaparse";
import PropTypes from "prop-types";
function SampleCSVFormat() {
const expectedHeaders = ["evaluatee", "email", "department", "course_code"];
const sampleData = [
{
evaluatee: "John Doe",
email: "johndoe@example.com",
department: "IT",
course_code: "IT101",
"Question 1": "The course content was relevant and useful.",
"Question 2": "The course was well-organized and easy to follow.",
},
{
evaluatee: "Jane Smith",
email: "janesmith@example.com",
department: "Marketing",
course_code: "MKT202",
"Question 1": "The course was engaging and interactive.",
"Question 2": "I would recommend this course to others.",
},
];
const csvFile = Papa.unparse({
fields: [...expectedHeaders, ...Object.keys(sampleData[0]).slice(4)],
data: sampleData,
});
// Time stamp for file name
const timeStamp = new Date().toISOString().replace(/:/g, "-");
// Download the new CSV file
const link = document.createElement("a");
link.href = URL.createObjectURL(new Blob([csvFile], { type: "text/csv" }));
link.download = `sample-csv-format-${timeStamp}.csv`;
link.click();
}
function CsvPreview({ file, rowCount = 5 }) {
CsvPreview.propTypes = {
file: PropTypes.any,
rowCount: PropTypes.number,
};
const [data, setData] = useState([]);
const [numRows, setNumRows] = useState(0);
const [numCols, setNumCols] = useState(0);
const [headersMatch, setHeadersMatch] = useState(false);
useEffect(() => {
if (file) {
Papa.parse(file, {
header: true,
complete: (results) => {
setData(results.data);
setNumRows(results.data.length);
setNumCols(Object.keys(results.data[0]).length);
// Check if first 4 headers match expected headers
const expectedHeaders = [
"evaluatee",
"email",
"department",
"course_code",
];
const firstFourHeaders = Object.keys(results.data[0]).slice(0, 4);
if (
JSON.stringify(firstFourHeaders) === JSON.stringify(expectedHeaders)
) {
setHeadersMatch(true);
} else {
setHeadersMatch(false);
// Generate new CSV file with sample data
SampleCSVFormat();
}
},
});
}
}, [file]);
return (
<>
<div className="flex flex-wrap justify-start items-center">
<h1 className="text-xl font-bold text-blue-500 py-2 md:mr-4">
Preview CSV File (First 5 Rows)
</h1>
<div
className={`p-4 max-w-fit rounded-lg ${
headersMatch
? "bg-green-100 border-green-400 text-green-700"
: "bg-red-100 border-red-400 text-red-700"
}`}
>
<p className="text-sm font-medium">
{headersMatch
? "Headers match expected first 4 headers"
: "Headers do not match expected headers. A sample CSV file has been generated and downloaded to your computer. Please use this file as a reference and try again."}
</p>
</div>
</div>
<p className="text-sm text-gray-500 mt-2">
{numRows} rows x {numCols} columns
</p>
<div className="overflow-auto overscroll-auto rounded-lg">
<table>
<thead>
<tr className="bg-blue-100">
{data.length > 0 &&
Object.keys(data[0]).map((key) => (
<th className="px-4 py-2 text-blue-500 truncate" key={key}>
{key}
</th>
))}
</tr>
</thead>
<tbody>
{data.slice(0, rowCount).map((row, index) => (
<tr className="bg-white" key={index}>
{Object.values(row).map((cell, cellIndex) => (
<td
className="px-4 py-2 text-gray-500 truncate"
key={cellIndex}
>
{cell}
</td>
))}
</tr>
))}
</tbody>
</table>
</div>
</>
);
}
/**
* @description Handles the admin prediction
*/
export default function AdminPrediction() {
const token = getCookie("token");
/**
* @description decode the jwt token and return the payload
*/
const loadProcessBy = () => {
httpClient
.get(`/user/get_user/${token}`)
.then((response) => {
toast.info(
`Get ready to analyze the data ${response.data.user.username}!`,
{
position: "bottom-center",
},
);
})
.catch((error) => {
toast.error(error.response.data.message);
// Remove cookie and token
signout();
window.location.href = "/login-timeout";
});
};
const [previousData, setPreviousData] = useState({
p_csv_question: "",
p_flag_deleted: "",
p_flag_release: "",
p_id: "",
p_school_semester: "",
p_school_year: "",
});
const {
p_csv_question,
p_flag_deleted,
p_flag_release,
p_id,
p_school_semester,
p_school_year,
} = previousData;
const get_previous_evaluated_file = () => {
httpClient.get("/data/get-previous-evaluated-file").then((response) => {
setPreviousData({
...previousData,
p_csv_question: response.data.p_csv_question,
p_flag_deleted: response.data.p_flag_deleted,
p_flag_release: response.data.p_flag_release,
p_id: response.data.p_id,
p_school_semester: response.data.p_school_semester,
p_school_year: response.data.p_school_year,
});
});
};
/**
* @description Process by state
*/
useEffect(() => {
if (isAuth().verified_email === "Verified") {
get_previous_evaluated_file();
loadProcessBy();
}
}, []);
const [csv_file_to_view, setCSVFileToView] = useState();
const [handlers, setHandlers] = useState({
buttonDisabled: false,
ok: false,
errorEffect: false,
errorMessage: "",
textChange: "Upload File",
okToAnS: false,
errorEffectToAnS: false,
errorMessageToAnS: "",
textChangeToAnS: "Analyze Sentiment and Save",
});
const {
buttonDisabled,
ok,
errorEffect,
errorMessage,
textChange,
okToAnS,
errorEffectToAnS,
errorMessageToAnS,
textChangeToAnS,
} = handlers;
const [timeAnalyze, setTimeAnalyze] = useState({
overall_time: "",
pre_formatter_time: "",
post_formatter_time: "",
tokenizer_time: "",
padding_time: "",
model_time: "",
prediction_time: "",
sentiment_time: "",
adding_predictions_time: "",
adding_to_db_time: "",
analysis_user_time: "",
analysis_department_time: "",
analysis_collection_time: "",
});
const {
overall_time,
pre_formatter_time,
post_formatter_time,
tokenizer_time,
padding_time,
model_time,
prediction_time,
sentiment_time,
adding_predictions_time,
adding_to_db_time,
analysis_user_time,
analysis_department_time,
analysis_collection_time,
} = timeAnalyze;
/**
* @description Handles the file upload
* @type {(function(*): void)|*}
*/
const onDrop = useCallback((acceptedFiles) => {
// Do something with the files
setCSVFileToView(acceptedFiles[0]);
setHandlers({
...handlers,
errorMessage: "",
});
}, []);
const { getRootProps, getInputProps, isDragActive, acceptedFiles } =
useDropzone({ onDrop });
/**
* @description Removes the file on call
*/
const removeAll = () => {
setCSVFileToView(null);
setHandlers({
...handlers,
errorMessage: "",
});
acceptedFiles.splice(0, acceptedFiles.length);
};
const [csv_columns, setCSVColumns] = useState({
csv_file_name: "",
csv_columns_to_pick: [],
});
const { csv_file_name, csv_columns_to_pick } = csv_columns;
const [selectedColumn, setSelectedColumn] = useState({
selected_column_for_sentence: "",
selected_column_for_evaluatee: "",
selected_column_for_department: "",
selected_column_for_course_code: "",
selected_semester: "",
});
const semester = [
{ name: "1st Semester", id: 1 },
{ name: "2nd Semester", id: 2 },
{ name: "3rd Semester", id: 3 },
{ name: "Summer", id: 4 },
];
const { selected_column_for_sentence, selected_semester } = selectedColumn;
const [extras, setExtras] = useState({
csv_question: "",
school_year: "",
});
const { csv_question, school_year } = extras;
/**
* @description For step counter in the forgot password form.
*/
const [count, setCount] = useState(1);
/**
* @description Reset and clears the error messages and when selects a column.
* @param name
* @returns {(function(*): void)|*}
*/
const handleSelect = (name) => (value) => {
setSelectedColumn({
...selectedColumn,
[name]: value,
});
setHandlers({
...handlers,
errorMessageToAnS: "",
});
setExtras({
...extras,
csv_question: "",
});
};
/**
* @description Gets the input from the user and sets the state
*/
const handleExtras = (name) => (event) => {
setExtras({ ...extras, [name]: event.target.value });
setHandlers({
...handlers,
errorMessageToAnS: "",
});
};
/**
* @description Handles the view of the csv file and to select the columns
* @param event
* @returns {Promise<void>}
*/
const handleSubmitCSVToView = async (event) => {
event.preventDefault();
setHandlers({
...handlers,
ok: true,
textChange: "Uploading File...",
});
const formData = new FormData();
formData.append("csv_file_to_view", csv_file_to_view);
await httpClient
.post("/data/view-columns", formData)
.then(async (response) => {
setHandlers({
...handlers,
ok: false,
showButtonToView: false,
textChange: "Upload File",
});
toast.success(response.data.message);
jwtVerify(
response.data.token_columns,
await importSPKI(MATRIX_RSA_PUBLIC_KEY, "RS256"),
).then((result) => {
setCSVColumns({
...csv_columns,
show_columns: true,
csv_file_name: result.payload.csv_file_name,
csv_columns_to_pick: result.payload.csv_columns,
});
});
setCount(count + 1);
})
.catch((error) => {
removeAll();
setCSVColumns({
...csv_columns,
show_columns: false,
csv_file_name: "",
});
setHandlers({
...handlers,
ok: false,
errorEffect: true,
errorMessage: error.response.data.message,
textChange: "Upload File",
}) || toast.error(error.message);
});
};
/**
* @description Resets the state back to the first step.
* @param type
* @returns {Promise<void>}
*/
const handleResetWhenDone = async (type) => {
setExtras({
...extras,
csv_question: "",
school_year: "",
});
setSelectedColumn({
...selectedColumn,
selected_column_for_sentence: "",
selected_semester: "",
});
setCSVColumns({
...csv_columns,
show_columns: true,
csv_file_name: "",
csv_columns_to_pick: [],
});
setHandlers({
...handlers,
textChange: "Upload File",
okToAnS: false,
errorEffectToAnS: false,
errorMessageToAnS: "",
textChangeToAnS: "Analyze Sentiment and Save",
});
setTimeAnalyze({
...timeAnalyze,
overall_time: "",
pre_formatter_time: "",
post_formatter_time: "",
tokenizer_time: "",
padding_time: "",
model_time: "",
prediction_time: "",
sentiment_time: "",
adding_predictions_time: "",
analysis_user_time: "",
analysis_department_time: "",
analysis_collection_time: "",
});
setCount(1);
await httpClient
.post("/data/delete-uploaded-csv-file", {
file_name: csv_file_name,
})
.then((response) => {
if (type === "done") {
toast.success(response.data.message);
get_previous_evaluated_file();
} else if (type === "cancel") {
toast.warning("Discard the changes");
} else {
toast.error("File deleted due to error.");
}
})
.catch((error) => {
toast.error(error.message);
});
removeAll();
};
/**
* @description Handles the analysis and saving of the csv file
* @param event
* @returns {Promise<void>}
*/
const handleSubmitToAnalyzeAndSave = async (event) => {
event.preventDefault();
setHandlers({
...handlers,
buttonDisabled: true,
okToAnS: true,
textChangeToAnS: "Processing File...",
});
const regex = /S\.Y\.\s\d{4}-\d{4}/;
if (!getNumberFromString(selected_column_for_sentence)) {
setHandlers({
...handlers,
okToAnS: false,
errorEffectToAnS: true,
errorMessageToAnS: "Select a source header column for sentence",
textChangeToAnS: "Analyze Sentiment and Save",
});
} else if (!regex.test(school_year)) {
setHandlers({
...handlers,
okToAnS: false,
errorEffectToAnS: true,
errorMessageToAnS: "Invalid school year format.",
textChangeToAnS: "Analyze Sentiment and Save",
});
} else if (!selected_semester) {
setHandlers({
...handlers,
okToAnS: false,
errorEffectToAnS: true,
errorMessageToAnS: "Select a school semester",
textChangeToAnS: "Analyze Sentiment and Save",
});
} else if (
getNameFromString(selected_column_for_sentence) !== csv_question
) {
setHandlers({
...handlers,
okToAnS: false,
errorEffectToAnS: true,
errorMessageToAnS:
"Question column does not match the selected column for sentence",
textChangeToAnS: "Analyze Sentiment and Save",
});
} else {
await httpClient
.post("/data/analyze-save-csv", {
file_name: csv_file_name,
csv_question,
school_year,
selected_column_for_sentence: getNumberFromString(
selected_column_for_sentence,
),
selected_semester,
token,
})
.then((response) => {
toast.success(response.data.message);
get_previous_evaluated_file();
setHandlers({
...handlers,
buttonDisabled: false,
okToAnS: false,
textChangeToAnS: "Analyze Sentiment and Save",
});
setTimeAnalyze({
...timeAnalyze,
overall_time: response.data.overall_time,
pre_formatter_time: response.data.pre_formatter_time,
post_formatter_time: response.data.post_formatter_time,
tokenizer_time: response.data.tokenizer_time,
padding_time: response.data.padding_time,
model_time: response.data.model_time,
prediction_time: response.data.prediction_time,
sentiment_time: response.data.sentiment_time,
adding_predictions_time: response.data.adding_predictions_time,
adding_to_db_time: response.data.adding_to_db_time,
analysis_user_time: response.data.analysis_user_time,
analysis_department_time: response.data.analysis_department_time,
analysis_collection_time: response.data.analysis_collection_time,
});
setCount(count + 1);
})
.catch((error) => {
setHandlers({
...handlers,
okToAnS: false,
errorEffectToAnS: true,
errorMessageToAnS: error.response.data.message,
textChangeToAnS: "Analyze Sentiment and Save",
});
});
}
};
return (
<div className="px-6 mx-auto max-w-7xl pt-8">
{isAuth().verified_email === "Verified" ? (
<>
<Header
body={
"Upload a CSV file to analyze and choose the column that contains the responses to analyze. The system will automatically create users but you have to manually send the credentials to them if the results are ready."
}
title={"Sentiment Analyzer"}
/>
<div className="grid grid-cols-1 py-8 md:grid-cols-3 gap-y-6 md:gap-6">
<div className="col-span-1 p-8 rounded-lg bg-blue-50 shadow col-start-2 md:col-start-auto">
<h1 className="mb-4 text-xl font-bold text-blue-500">
Right Format of CSV File to Upload
</h1>
<p className="mb-4 text-sm text-gray-500 font-medium">
Your CSV file should contain the following headers:{" "}
<b className="text-transparent bg-clip-text bg-gradient-to-r from-blue-500 to-teal-500">
evaluatee, email, department, course code
</b>{" "}
and pick a header for the{" "}
<b className="text-transparent bg-clip-text bg-gradient-to-r from-blue-500 to-teal-500">
sentence
</b>
.
</p>
<p className="mb-4 text-sm text-gray-500 font-medium">
<b className="text-transparent bg-clip-text bg-gradient-to-r from-blue-500 to-teal-500">
sentence
</b>{" "}
is the header that contains the responses of the students.
</p>
<button
className={`mb-4 px-8 py-1 flex flex-row justify-center ${ACCENT_BUTTON} ${
buttonDisabled &&
`opacity-50 cursor-not-allowed pointer-events-none`
}`}
disabled={buttonDisabled}
onClick={() => {
SampleCSVFormat();
}}
type="button"
>
<FontAwesomeIcon
className={`${ICON_PLACE_SELF_CENTER}`}
icon={faFileCsv}
/>
Download Sample CSV File
</button>
<h1 className="mb-4 text-xl font-bold text-blue-500">
System's First Run
</h1>
<p className="mb-4 text-sm text-gray-500 font-medium">
On the first run, the system will take a long time to analyze
and save the data. This is because the system is{" "}
<b className="text-transparent bg-clip-text bg-gradient-to-r from-blue-500 to-teal-500">
automatically creates user accounts
</b>{" "}
and saves the results to there respective database based on the
user's full name.{" "}
<b className="text-transparent bg-clip-text bg-gradient-to-r from-blue-500 to-teal-500">
but it still depends on the size of the data to analyze and
save.
</b>
</p>
<h1 className="mb-4 text-xl font-bold text-blue-500">
Account Credentials
</h1>
<p className="mb-4 text-sm text-gray-500 font-medium">
Admin will send the credentials to the users if the results are
ready right through their email. You can manage these accounts
in the{" "}
<span className="font-bold text-transparent bg-clip-text bg-gradient-to-r from-blue-500 to-teal-500">
<Link to={"/admin/management/users/professors"}>
User management
</Link>
</span>{" "}
page.
</p>
</div>
<div className="col-span-2 row-start-1 md:row-start-auto">
<div
className={`flex flex-col w-full bg-blue-50 rounded-lg shadow ${
errorEffect || errorEffectToAnS
? `animate-wiggle outline outline-2`
: ""
}`}
onAnimationEnd={() =>
setHandlers({
...handlers,
errorEffect: false,
errorEffectToAnS: false,
})
}
>
<div className="grid w-full h-full grid-cols-1 md:grid-cols-5">
<div className="flex flex-col w-full h-full col-span-5 p-8 pb-8 space-y-4">
{p_id === "" ? (
""
) : (
<>
<h1 className="text-xl font-bold text-blue-500">
Quick view
</h1>
<div className="flex flex-col w-full">
<DisclosureTogglable
title={"Previously Evaluated Columns"}
>
<div className="space-y-2">
<h1 className="text-gray-500 font-medium">
ID - {p_id}
</h1>
<h1 className="text-gray-500 font-medium">
Evaluated Column - {p_csv_question}
</h1>
<h1 className="text-gray-500 font-medium">
School Year - {p_school_year} @{" "}
{p_school_semester}
</h1>
<h1 className="text-gray-500 font-medium">
Published - {p_flag_release}
</h1>
<h1 className="text-gray-500 font-medium">
Deleted (Temporary) - {p_flag_deleted}
</h1>
</div>
</DisclosureTogglable>
</div>
</>
)}
<h1 className="text-xl font-bold text-blue-500">
{count === 1
? "Upload CSV File"
: count === 2
? "Header Selection"
: "Time elapsed"}
</h1>
<h1 className="font-medium">
{count === 3
? `${timeFormat(overall_time)}`
: `Step ${count} of 2`}
</h1>
{count === 1 ? (
<form
encType={"multipart/form-data"}
onSubmit={handleSubmitCSVToView}
>
<div className="p-2 rounded bg-yellow-100 mb-4">
<h1 className="text-sm font-medium text-yellow-500">
<b>Note:</b> Make sure that the CSV file contains
the overall data before uploading. Mismatched data
from the previous analyzed CSV file will be
rejected. If you want to analyze a new CSV file
which contains new set of professors and
departments, please archive all/previous the data
first.
</h1>
</div>
<div className="flex flex-col space-y-4">
<div className="flex flex-col w-full space-y-2">
<div
className="flex items-center justify-center w-full"
{...getRootProps()}
>
<label
className={`flex flex-col items-center justify-center w-full h-64 border-2 border-dashed rounded-lg cursor-pointer bg-gray-50 hover:bg-gray-100 ${
errorEffect || errorEffectToAnS
? `animate-wiggle border-red-500`
: "border-gray-300"
}`}
htmlFor="dropzone-file"
>
<div className="flex flex-col items-center justify-center pt-5 pb-6">
<svg
aria-hidden="true"
className="w-10 h-10 mb-3 text-gray-400"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
/>
</svg>
<p className="mb-2 text-sm text-gray-500">
<span className="font-semibold">
Click to upload
</span>{" "}
or drag and drop
</p>
<p className="text-xs text-gray-500">
CSV files only
</p>
</div>
<input {...getInputProps()} />
{isDragActive ? (
<p className="text-sm text-gray-500">
Drop the files here ...
</p>
) : (
<p className="text-sm text-gray-500 px-4">
Drag 'n' drop some files here, or
click to select files
</p>
)}
{acceptedFiles.map((file) => (
<>
<p
className="px-4 text-base font-bold text-transparent bg-clip-text bg-gradient-to-r from-blue-500 to-teal-500"
key={file.path}
>
{file
? `${file.path} - ${file.size} bytes`
: ""}
</p>
</>
))}
</label>
</div>
<p
className="mt-1 text-sm text-gray-500"
id="file_input_help"
>
The file must be a .csv file.
</p>
</div>
</div>
<div className="flex space-y-2 overscroll-auto overflow-auto">
{acceptedFiles.map((file) => (
<div key={file.size}>
<CsvPreview file={file} />
</div>
))}
</div>
{/* Error message */}
{errorMessage ? (
<div className="mt-2 text-sm font-semibold text-red-500">
{errorMessage}
</div>
) : null}
<div className="flex flex-col justify-end w-full mt-8 lg:flex-row lg:space-x-2">
<div className="p-1" />
<button
className={`px-8 py-1 flex flex-row justify-center ${ACCENT_BUTTON}`}
type="submit"
>
{ok ? <LoadingAnimation /> : null}
{textChange}
</button>
</div>
</form>
) : count === 2 ? (
<form onSubmit={handleSubmitToAnalyzeAndSave}>
<div className="flex flex-col space-y-4">
<p className="text-gray-500">
Select the header that contains the responses to be
analyzed. The responses should be in the form of a
sentence. For example, “I like the
teacher“.
</p>
<div className="flex flex-col w-full space-y-2">
<h1 className="text-base font-medium text-blue-500">
File Name
</h1>
<input
className={`${TEXT_FIELD} cursor-not-allowed text-gray-500 bg-white ${
buttonDisabled &&
`opacity-50 cursor-not-allowed pointer-events-none`
}`}
disabled
placeholder="File Name"
type="text"
value={csv_file_name}
/>
</div>
<div className="flex flex-col w-full space-y-2">
<Listbox
disabled={buttonDisabled}
name={"sentence"}
onChange={handleSelect(
"selected_column_for_sentence",
)}
>
<Listbox.Label className="block text-base font-medium text-blue-500">
Sentence
</Listbox.Label>
<div className="relative mt-1">
<Listbox.Button
className={`${TEXT_FIELD} text-gray-500 bg-white ${
buttonDisabled &&
`opacity-50 cursor-not-allowed pointer-events-none`
}`}
>
<span className="block truncate text-start">
{selected_column_for_sentence
? selected_column_for_sentence
: "Select a column"}
</span>
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
<ChevronUpDownIcon
aria-hidden="true"
className="h-5 w-5 text-blue-500"
/>
</span>
</Listbox.Button>
<Transition
as={Fragment}
enter="transition duration-100 ease-out"
enterFrom="transform scale-95 opacity-0"
enterTo="transform scale-100 opacity-100"
leave="transition duration-75 ease-out"
leaveFrom="transform scale-100 opacity-100"
leaveTo="transform scale-95 opacity-0"
>
<Listbox.Options className="z-50 absolute mt-1 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm">
{csv_columns_to_pick.map((column) => (
<Listbox.Option
className={({ active }) =>
`relative cursor-default select-none py-2 pl-10 pr-4 ${
active
? "bg-blue-100 text-blue-500"
: "text-gray-500"
}`
}
key={column.id}
value={`${column.id} - ${column.name}`}
>
{({ selected }) => (
<>
<span
className={`block truncate ${
selected
? "font-medium"
: "font-normal"
}`}
>
{`${column.id} - ${column.name}`}
</span>
{selected ? (
<span className="absolute inset-y-0 left-0 flex items-center pl-3 text-blue-500">
<CheckIcon
aria-hidden="true"
className="h-5 w-5"
/>
</span>
) : null}
</>
)}
</Listbox.Option>
))}
</Listbox.Options>
</Transition>
</div>
</Listbox>
</div>
<div className="flex flex-col w-full space-y-2">
<h1 className="text-base font-medium text-blue-500">
School Year (e.g. S.Y. 2020-2021)
</h1>
<input
className={`truncate ${TEXT_FIELD} text-gray-500 bg-white ${
buttonDisabled &&
`opacity-50 cursor-not-allowed pointer-events-none`
}`}
disabled={buttonDisabled}
name="school_year"
onChange={handleExtras("school_year")}
placeholder="S.Y. 2020-2021"
type="text"
value={school_year}
/>
<Listbox
disabled={buttonDisabled}
name={"semester"}
onChange={handleSelect("selected_semester")}
>
<Listbox.Label className="block text-base font-medium text-blue-500">
Semester
</Listbox.Label>
<div className="relative mt-1">
<Listbox.Button
className={`${TEXT_FIELD} text-gray-500 bg-white ${
buttonDisabled &&
`opacity-50 cursor-not-allowed pointer-events-none`
}`}
>
<span className="block truncate text-start">
{selected_semester
? selected_semester
: "Select a semester"}
</span>