ayesha-21 commited on
Commit
ac83dbe
·
verified ·
1 Parent(s): f15a4d9

Upload odt_evaluator.py

Browse files
Files changed (1) hide show
  1. odt_evaluator.py +119 -0
odt_evaluator.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import sys
4
+
5
+ ODT = "/home/user/Proposals/Project_Alpha_final.odt"
6
+ TMP_XML = "/tmp/content.xml"
7
+
8
+
9
+ def emit(msg: str):
10
+ print(msg)
11
+
12
+
13
+ # =================================================
14
+ # 1. File existence
15
+ # =================================================
16
+ if not os.path.isfile(ODT):
17
+ emit("FILE_MISSING")
18
+ sys.exit(0)
19
+
20
+ emit("FILE_OK")
21
+
22
+
23
+ # =================================================
24
+ # 2. Extract content.xml
25
+ # =================================================
26
+ try:
27
+ with open(TMP_XML, "w", encoding="utf-8") as out:
28
+ subprocess.run(
29
+ ["unzip", "-p", ODT, "content.xml"],
30
+ stdout=out,
31
+ stderr=subprocess.DEVNULL,
32
+ check=True
33
+ )
34
+ except Exception:
35
+ emit("CONTENT_MISSING")
36
+ sys.exit(0)
37
+
38
+ emit("CONTENT_OK")
39
+
40
+
41
+ # =================================================
42
+ # 3. Load XML safely
43
+ # =================================================
44
+ with open(TMP_XML, "r", encoding="utf-8", errors="ignore") as f:
45
+ xml = f.read()
46
+
47
+ # Anti-reward-hacking: ensure document is not empty
48
+ if len(xml.strip()) < 800:
49
+ emit("CONTENT_MISSING")
50
+ sys.exit(0)
51
+
52
+
53
+ # =================================================
54
+ # 4. Manual page break (page-2 proxy)
55
+ # =================================================
56
+ page_break_pos = xml.find("<text:soft-page-break")
57
+
58
+ if page_break_pos != -1:
59
+ emit("PAGE_BREAK_AFTER_P1_OK")
60
+ else:
61
+ emit("PAGE_BREAK_MISSING")
62
+
63
+
64
+ # =================================================
65
+ # 5. Table of Contents checks
66
+ # =================================================
67
+ toc_pos = xml.find("<text:table-of-content")
68
+
69
+ # Presence
70
+ if toc_pos != -1:
71
+ emit("TOC_PRESENT_OK")
72
+ else:
73
+ emit("TOC_MISSING")
74
+ sys.exit(0) # no point checking further TOC properties
75
+
76
+ # Placement: must be after page break (proxy for page 2)
77
+ if not (page_break_pos != -1 and toc_pos > page_break_pos):
78
+ emit("TOC_NOT_ON_PAGE2")
79
+
80
+ # TOC title
81
+ if "Proposal Outline" in xml:
82
+ emit("TOC_TITLE_OK")
83
+ else:
84
+ emit("TOC_TITLE_BAD")
85
+
86
+ # TOC level restriction
87
+ if 'text:outline-level="1"' in xml:
88
+ emit("TOC_LEVEL_OK")
89
+ else:
90
+ emit("TOC_LEVEL_BAD")
91
+
92
+
93
+ # =================================================
94
+ # 6. Image checks
95
+ # =================================================
96
+ img_pos = xml.find("<draw:image")
97
+
98
+ if img_pos != -1:
99
+ emit("IMG_PRESENT_OK")
100
+ else:
101
+ emit("IMG_MISSING")
102
+
103
+ # Image must be below TOC
104
+ if img_pos != -1 and img_pos > toc_pos:
105
+ emit("IMG_BELOW_TOC_OK")
106
+ else:
107
+ emit("IMG_ABOVE_TOC")
108
+
109
+ # Anchor type
110
+ if 'text:anchor-type="as-char"' in xml:
111
+ emit("ANCHOR_OK")
112
+ else:
113
+ emit("ANCHOR_BAD")
114
+
115
+ # Width exactly 15 cm
116
+ if 'svg:width="15cm"' in xml or 'svg:width="150mm"' in xml:
117
+ emit("WIDTH_OK")
118
+ else:
119
+ emit("WIDTH_BAD")