forked from TexaProject/texa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
229 lines (189 loc) · 6.62 KB
/
main.go
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
package main
import (
"crypto/md5"
"fmt"
"html/template"
"io"
"net/http"
"os"
"regexp"
"strconv"
"time"
//Import this by exec in CLI: `go get -u github.com/TexaProject/texalib`
"github.com/TexaProject/texajson"
"github.com/TexaProject/texalib"
)
// AIName exports form value from /welcome globally
var AIName string
// IntName exports form value from /texa globally
var IntName string
func rootHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/welcome", 301)
}
func texaHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("method:", r.Method) //get request method
if r.Method == "GET" {
t, _ := template.ParseFiles("www/index.html")
t.Execute(w, nil)
} else {
r.ParseForm()
// fmt.Printf("%+v\n", r.Form)
fmt.Fprint(w, "<html><head><link rel=\"stylesheet\" href=\"http://localhost:3030/css/bootstrap.min.css\"><title>File Ack | TEXA Project</title></head><body>ACKNOWLEDGEMENT: Received the scores. <br /><br />Info:<br />")
fmt.Fprint(w, "<br /><br />VISIT: /result for interrogation.")
fmt.Fprintf(w, "<br /><br /><input type=\"button\" class=\"btn info\" onclick=\"location.href='http://localhost:3030/result';\" value=\"Visit /result\" /></body></html>")
fmt.Println("--INTERROGATION FORM DATA--")
IntName = r.Form.Get("IntName")
QSA := r.Form.Get("scoreArray")
SlabName := r.Form.Get("SlabName")
slabSequence := r.Form.Get("slabSequence")
fmt.Println("###", AIName)
fmt.Println("###", IntName)
fmt.Println("###", QSA)
fmt.Println("###", SlabName)
fmt.Println("###", slabSequence)
// LOGIC
re := regexp.MustCompile("[0-1]+")
array := re.FindAllString(QSA, -1)
SlabNameArray := regexp.MustCompile("[,]").Split(SlabName, -1)
slabSeqArray := regexp.MustCompile("[,]").Split(slabSequence, -1)
fmt.Println("###Resulting Array:")
for x := range array {
fmt.Println(array[x])
}
fmt.Println("###SlabNameArray: ")
fmt.Println(SlabNameArray)
fmt.Println("###slabSeqArray: ")
fmt.Println(slabSeqArray)
ArtiQSA := texalib.Convert(array)
fmt.Println("###ArtiQSA:")
fmt.Println(ArtiQSA)
HumanQSA := texalib.SetHumanQSA(ArtiQSA)
fmt.Println("###HumanQSA:")
fmt.Println(HumanQSA)
TSA := texalib.GetTransactionSeries(ArtiQSA, HumanQSA)
fmt.Println("###TSA:")
fmt.Println(TSA)
ArtiMts := texalib.GetMeanTestScore(ArtiQSA)
HumanMts := texalib.GetMeanTestScore(HumanQSA)
fmt.Println("###ArtiMts: ", ArtiMts)
fmt.Println("###HumanMts: ", HumanMts)
PageArray := texajson.GetPages()
fmt.Println("###PageArray")
fmt.Println(PageArray)
for _, p := range PageArray {
fmt.Println(p)
}
newPage := texajson.ConvtoPage(AIName, IntName, ArtiMts, HumanMts)
PageArray = texajson.AddtoPageArray(newPage, PageArray)
fmt.Println("###AddedPageArray")
fmt.Println(PageArray)
JsonPageArray := texajson.ToJson(PageArray)
fmt.Println("###jsonPageArray:")
fmt.Println(JsonPageArray)
////
fmt.Println("### SLAB LOGIC")
slabPageArray := texajson.GetSlabPages()
fmt.Println("###slabPageArray")
fmt.Println(slabPageArray)
slabPages := texajson.ConvtoSlabPage(ArtiQSA, SlabNameArray, slabSeqArray)
fmt.Println("###slabPages")
fmt.Println(slabPages)
for z := 0; z < len(slabPages); z++ {
slabPageArray = texajson.AddtoSlabPageArray(slabPages[z], slabPageArray)
}
fmt.Println("###finalslabPageArray")
fmt.Println(slabPageArray)
JsonSlabPageArray := texajson.SlabToJson(slabPageArray)
fmt.Println("###JsonSlabPageArray: ")
fmt.Println(JsonSlabPageArray)
////
fmt.Println("### CAT LOGIC")
CatPageArray := texajson.GetCatPages()
fmt.Println("###CatPageArray")
fmt.Println(CatPageArray)
CatPages := texajson.ConvtoCatPage(AIName, slabPageArray, SlabNameArray)
fmt.Println("###CatPages")
fmt.Println(CatPages)
CatPageArray = texajson.AddtoCatPageArray(CatPages, CatPageArray)
// for z := 0; z < len(CatPages); z++ {
// CatPageArray = texajson.AddtoCatPageArray(CatPages[z], CatPageArray)
// }
fmt.Println("###finalCatPageArray")
fmt.Println(CatPageArray)
JsonCatPageArray := texajson.CatToJson(CatPageArray)
fmt.Println("###JsonCatPageArray: ")
fmt.Println(JsonCatPageArray)
}
}
func welcomeHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("method:", r.Method) //get request method
if r.Method == "GET" {
t, _ := template.ParseFiles("www/welcome.html")
t.Execute(w, nil)
} else {
r.ParseForm()
}
}
// upload logic
func uploadHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("method:", r.Method)
if r.Method == "GET" {
crutime := time.Now().Unix()
h := md5.New()
io.WriteString(h, strconv.FormatInt(crutime, 10))
token := fmt.Sprintf("%x", h.Sum(nil))
t, _ := template.ParseFiles("login.html")
t.Execute(w, token)
} else {
r.ParseMultipartForm(32 << 20)
file, handler, err := r.FormFile("uploadfile")
if err != nil {
fmt.Println(err)
return
}
handler.Filename = "elizadata.js"
AIName = r.FormValue("AIName")
fmt.Println(AIName)
defer file.Close()
fmt.Fprint(w, "<html><head><link rel=\"stylesheet\" href=\"http://localhost:3030/css/bootstrap.min.css\"><title>File Ack | TEXA Project</title></head><body>ACKNOWLEDGEMENT: Uploaded the file. <br /><br />Header Info:<br />")
fmt.Fprintf(w, "%v", handler.Header)
fmt.Fprintf(w, "<br /><br />Saved As: www/js/"+handler.Filename)
fmt.Fprint(w, "<br /><br />VISIT: /texa for interrogation.")
fmt.Fprintf(w, "<br /><br /><input type=\"button\" class=\"btn info\" onclick=\"location.href='http://localhost:3030/texa';\" value=\"Visit /texa\" /></body></html>")
f, err := os.OpenFile("./www/js/"+handler.Filename, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Selected file: ", handler.Filename)
defer f.Close()
io.Copy(f, file)
// http.Redirect(w, r, "/texa", 301)
}
}
func resultHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("method:", r.Method) //get request method
if r.Method == "GET" {
t, _ := template.ParseFiles("www/result.html")
t.Execute(w, nil)
} else {
r.ParseForm()
}
}
func main() {
fmt.Println("--TEXA SERVER--")
fmt.Println("STATUS: INITIATED")
fmt.Println("ADDR: http://127.0.0.1:3030")
fsc := http.FileServer(http.Dir("www/css"))
http.Handle("/css/", http.StripPrefix("/css/", fsc))
fsj := http.FileServer(http.Dir("www/js"))
http.Handle("/js/", http.StripPrefix("/js/", fsj))
fsd := http.FileServer(http.Dir("www/data"))
http.Handle("/data/", http.StripPrefix("/data/", fsd))
http.HandleFunc("/", rootHandler)
http.HandleFunc("/welcome", welcomeHandler)
http.HandleFunc("/upload", uploadHandler)
http.HandleFunc("/texa", texaHandler)
http.HandleFunc("/result", resultHandler)
http.ListenAndServe(":3030", nil)
}