Skip to content

Commit 5353935

Browse files
author
lmh
committed
extract feedback pdfs
1 parent a4f3a51 commit 5353935

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# optmize level
1818
optimize=1
1919
# version
20-
version="0.2"
20+
version="0.3"
2121

2222
def generate_version():
2323
local_repo = git.Repo(".")

mbzbot.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
__author__ = "tna76874"
88
__credits__ = ["https://github.com/Swarthmore/extract-mbz"]
99
__license__ = "GPL"
10-
__version__ = "0.1"
10+
__version__ = "0.3"
1111
__maintainer__ = "tna76874"
1212
__email__ = "dev@hilberg.eu"
1313
__status__ = "Prototype"
@@ -163,14 +163,18 @@ def extractmbz(self,zfile):
163163
DF_tmp = pd.concat([DF_tmp.reset_index(drop=True),pd.DataFrame.from_dict(dict(DF_tmp['assign']['activity']),orient='index').T.reset_index(drop=True)],axis=1,sort=False)
164164
DF_tmp.drop(columns=['assign','@id','timemodified'],inplace=True)
165165
DF_assign = pd.concat([DF_assign,DF_tmp])
166-
166+
167167
# merge item informations
168168
DF_items = pd.concat([DF_assign,DF_resource])
169169
DF_files = pd.merge(DF_files,DF_items,on="contextid")
170170
DF_files = pd.merge(DF_files,DF_things,left_on="contenthash",right_on="filen",how="outer")
171+
172+
# Dataframes to work with
173+
DF_feedback = DF_files[DF_files['filearea']=='download'].rename(columns = {'@contextid':'contextid','@id':'id1'})
171174
DF_files = pd.merge(DF_files,DF_user,left_on="userid",right_on="id2")
172-
173-
#convert course files
175+
DF_assign = DF_files[DF_files['component'].str.contains('assign')]
176+
177+
# convert course files
174178
for i in DF_things[DF_things['filen']=='section.xml']['path']:
175179
DF_resource = pdx.read_xml(i).T.reset_index(drop=True)
176180
try:
@@ -185,8 +189,7 @@ def extractmbz(self,zfile):
185189
shutil.move(os.path.abspath(folderpath+'/'+DF_filescopy.loc[j,'filen']),os.path.abspath(folderpath+'/'+DF_filescopy.loc[j,'filen'][:4] + '_' + DF_filescopy.loc[j,'filename']))
186190
except: pass
187191

188-
#convert assignment files
189-
DF_assign = DF_files[DF_files['component'].str.contains('assign')]
192+
# convert assignment files
190193
for i in DF_assign.index:
191194
try:
192195
name = DF_assign.loc[i,'lastname'].replace(' ','_')+'_'+DF_assign.loc[i,'firstname']
@@ -198,7 +201,20 @@ def extractmbz(self,zfile):
198201
shutil.copy(DF_assign.loc[i,'path'],folderpath)
199202
shutil.move(os.path.abspath(folderpath+'/'+DF_assign.loc[i,'filen']),os.path.abspath(folderpath+'/'+hashval+'_'+DF_assign.loc[i,'filename']))
200203
except: pass
201-
204+
205+
# convert feedbacks
206+
for i in DF_feedback.index:
207+
try:
208+
name = DF_feedback.loc[i,'filename'].split(".")[0]
209+
assignment = DF_feedback.loc[i,'name']
210+
hashval = DF_feedback.loc[i,'contenthash'][:5]
211+
folderpath = os.path.join(os.path.abspath(self.exportdir), 'feedback' , assignment, name)
212+
if not os.path.exists(folderpath):
213+
os.makedirs(folderpath)
214+
shutil.copy(DF_feedback.loc[i,'path'],folderpath)
215+
shutil.move(os.path.abspath(folderpath+'/'+DF_feedback.loc[i,'filen']),os.path.abspath(folderpath+'/'+hashval+'_'+DF_feedback.loc[i,'filename']))
216+
except: pass
217+
202218
# delete the extracted mbz files
203219
shutil.rmtree(self.extractdir)
204220
# zip all extracted files into one file

0 commit comments

Comments
 (0)