-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfillGradingList.fsx
86 lines (68 loc) · 3.14 KB
/
fillGradingList.fsx
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
let gradingListId = "1IkoCocAKy5hb6KfMHEOlIZG5RAdZwFnm77RaoUhDMAc"
let secondCourseSpreadsheetId = "17TxV9OgKSN37RaFiGRgRe_T45E20YtODrnn5U3q3P9k"
let thirdCourseSpreadsheetId ="1zUMT5TkjDuiwjABzu-83n972tlx0Jg1b_wwZcYFzLQs"
let fourthCourseSpreadsheetId = "12ypnsGlkpD1hJa_n2J9QWOxwbIClXf67bALYH0mr8d0"
let registrationListId = "13eC38aia4WwysOUCYcDKeH2Sfi2hwIBARNjmeoN8x_Q"
let registrationRangeStart = 63
let registrationRangeEnd = 72
#r "nuget: Google.Apis.Sheets.v4"
#load "DocUtils/DocUtils/GoogleSheetsUtils.fs"
open DocUtils
type Student =
{
Surname: string
Course: string
FullName: string
Theme: string
}
let collectStudents (service: GoogleSheetService) =
let sheet = service.Sheet(registrationListId, "Sheet1")
let rawData = sheet.ReadColumn ("B", registrationRangeStart, registrationRangeEnd - registrationRangeStart + 1)
rawData
|> Seq.filter ((<>) "")
|> Seq.map (fun s ->
let splittedRow = s.Split(' ')
{
Surname = splittedRow[0]
Course = splittedRow[2]
FullName = ""
Theme = ""
}
)
let updateStudentFullNamesAndThemes (service: GoogleSheetService) (data: seq<Student>) =
let getInfo id = service.Sheet(id, "СП").ReadByHeaders(["ФИО"; "Тема"]) |> Seq.map (fun map -> (map["ФИО"], map["Тема"]))
let secondCourseInfo = getInfo secondCourseSpreadsheetId
let thirdCourseInfo = getInfo thirdCourseSpreadsheetId
let fourthCourseInfo = getInfo fourthCourseSpreadsheetId
let infos = Seq.concat [secondCourseInfo; thirdCourseInfo; fourthCourseInfo]
let findInfo surname =
let fullNameCandidates = infos |> Seq.filter (fun (n, _) -> n.Split(' ')[0] = surname) |> Seq.toList
match fullNameCandidates with
| [] -> printfn "No info for %s" surname; ("", "")
| [n] -> n
| n :: _ :: _ -> printfn "Multiple full names for %s" surname; n
data |> Seq.map (fun student ->
let fullName, theme = findInfo student.Surname
{ student with FullName = fullName; Theme = theme})
let generateGradingList (service: GoogleSheetService) (data: seq<Student>) =
let sheetIds = service.Spreadsheet(gradingListId).Sheets() |> Seq.filter ((<>) "Итого")
let mainSheet = service.Spreadsheet(gradingListId).Sheet("Итого")
let write column mapper =
let info = Seq.concat [data |> Seq.map mapper; Seq.replicate 10 ""]
mainSheet.WriteColumn (column, info, 7)
write "A" (fun s -> s.FullName)
write "B" (fun s -> s.Theme)
write "C" (fun s -> s.Course)
for id in sheetIds do
let write column mapper =
let sheet = service.Spreadsheet(gradingListId).Sheet(id)
let info = Seq.concat [data |> Seq.map mapper; Seq.replicate 10 ""]
sheet.WriteColumn (column, info, 4)
write "A" (fun s -> s.FullName)
let main() =
use service = new GoogleSheetService("../credentials.json", "TeachingScripts")
let data = collectStudents service
let data = updateStudentFullNamesAndThemes service data
generateGradingList service data
()
main()