Skip to content

Commit

Permalink
put in arithmetic type questions, in progress draft
Browse files Browse the repository at this point in the history
  • Loading branch information
amygoldlist committed Nov 17, 2023
1 parent 2ece8fb commit 8f5461d
Show file tree
Hide file tree
Showing 9 changed files with 507 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Arithimetic_in_R/README_Arithmetic.md
@@ -0,0 +1,10 @@
## Read Me

In progress.


Notes:
* alter your xlsx file
* run script
* zip the folder that appears in output.
* upload to D2L!
129 changes: 129 additions & 0 deletions Arithimetic_in_R/XLSX_to_XML.R
@@ -0,0 +1,129 @@
#################################################################
##
## Create a zipped xml file to upload to D2L
## Input = XLSX (or should it be CSV?)
## Amy_note = could we put the title somewhere? does it matter?
##
#################################################################

## libraries
library(tidyverse)
library(openxlsx)
library(xml2)

## Read in data
df <- read.xlsx("data/Base_file.xlsx")
xml_qq <- read_xml("data/questiondb_base.xml")

############################
## add the date to the filename, could expand!
############################


## 1. find the correct node:
title_node <- xml_find_all(xml_qq, xpath = ".//section")

## 2. Write it to the correct attribute. Attributes!!
xml_attr(title_node,attr = "title") <- paste0("arithmetic_section_", Sys.Date())

print("Wrote the title. Starting the next phase....")


## Loop over the dataframe:
for (i in (1:nrow(df) )){
print(paste("Number of questions to get to: ", nrow(df)))
print(paste("Adding question ", i))
#### create a new question?

## identify the item
qq_set <- xml_find_all(xml_qq, xpath = ".//item")
qq_node <- qq_set[i]

## this step is unneccessary
#new_q <- qq_node

xml_attr(qq_node,attr = "title") <- df$Title[i]
xml_attr(qq_node,attr = "id") <- df$N[i]
xml_attr(qq_node,attr = "ident") <- paste0("OBJ_",df$N[i])
xml_attr(qq_node,attr = "label") <- paste0("QUES_",df$N[i])


question_node <- xml_find_first(qq_node, xpath = ".// mattext")
xml_text(question_node) <- df$Question[i]


ans_set <- xml_find_all(qq_node,xpath = ".// formula")
for (j in (1:length(ans_set))){
ans_node <- ans_set[j]
xml_text(ans_node)<- as.character(df$Answer[i])
}



qnode2 <- xml_find_first(qq_node, xpath = ".//response_num")
xml_attr(qnode2, attr = "ident") <- paste0("QUES_",df$N[i],"_NUM")

qnode2 <- xml_find_first(qq_node, xpath = ".//response_label")
##inspect
#xml_attrs(qnode2)
xml_attr(qnode2, attr = "ident") <- paste0("QUES_",df$N[i],"_A1")


### This is worthy of a function!!
qnode2 <- xml_find_first(qq_node, xpath = ".//response_str")
##inspect
#xml_attrs(qnode2)
xml_attr(qnode2, attr = "ident") <- paste0("QUES_",df$N[i],"_STR")


## precision!
qnode2 <- xml_find_all(qq_node, xpath = ".//precision")
#xml_attrs(qnode2)

xml_text(qnode2) <- as.character(df$Precision[i])
#xml_attr(qnode2, attr = "precision_enforced") <- "no"

qnode2 <- xml_find_all(qq_node, xpath = ".//tolerance")
xml_attrs(qnode2)

xml_text(qnode2) <- as.character(df$Tolerance[i])



## feedback?
qnode2 <- xml_find_all(qq_node, xpath = ".//itemfeedback")
qnode3 <- xml_find_all(qnode2, xpath = ".//mattext")
xml_text(qnode3) <- df$feedback[i]
xml_attr(qnode2, attr = "ident") <- paste0("QUES_", df$N[i])

## hint?
qnode2 <- xml_find_all(qq_node, xpath = ".//hintmaterial")
qnode3 <- xml_find_all(qnode2, xpath = ".//mattext")
xml_text(qnode3) <- df$Hint[i]

## maybe create a new node?
if (i< nrow(df)){
print("creating a new question")
xml_add_sibling(qq_node, .value =qq_node, where = "after", .copy = TRUE)
}
}


### Print to file


##write_xml(xml_qq, "hi.xml") #Test!


## The whole kit and caboodle
## create a new folder:
folder_name <- paste0("output\arithmetic_section_", Sys.Date())
dir.create(folder_name)
write_xml(xml_qq, paste0(folder_name,"\\questiondb.xml"))
## move the other file?

manifest <- read_xml("data\imsmanifest.xml")
write_xml(manifest, paste0(folder_name,"\\imsmanifest.xml"))



Binary file added Arithimetic_in_R/data/Base_file.xlsx
Binary file not shown.
6 changes: 6 additions & 0 deletions Arithimetic_in_R/data/imsmanifest.xml
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest identifier="MANIFEST_1" xmlns:d2l_2p0="http://desire2learn.com/xsd/d2lcp_v2p0" xmlns="http://www.imsglobal.org/xsd/imscp_v1p1">
<resources>
<resource identifier="res_question_library" type="webcontent" d2l_2p0:material_type="d2lquestionlibrary" href="questiondb.xml" />
</resources>
</manifest>
104 changes: 104 additions & 0 deletions Arithimetic_in_R/data/questiondb_base.xml
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<questestinterop>
<objectbank ident="QLIB_1" xmlns:d2l_2p0="http://desire2learn.com/xsd/d2lcp_v2p0">
<section d2l_2p0:id="1" ident="SECT_1" title="Section-arithmatic">
<presentation_material>
<flow_mat>
<flow_mat>
<material>
<mattext texttype="text/plain">Created by R</mattext>
</material>
</flow_mat>
</flow_mat>
</presentation_material>
<sectionproc_extension>
<d2l_2p0:display_section_name>no</d2l_2p0:display_section_name>
<d2l_2p0:display_section_line>no</d2l_2p0:display_section_line>
<d2l_2p0:type_display_section>0</d2l_2p0:type_display_section>
</sectionproc_extension>


<item d2l_2p0:id="4" ident="OBJ_1006" label="QUES_1005" d2l_2p0:page="1" title="real no variable problem" >
<itemmetadata>
<qtimetadata>
<qti_metadatafield>
<fieldlabel>qmd_computerscored</fieldlabel>
<fieldentry>yes</fieldentry>
</qti_metadatafield>
<qti_metadatafield>
<fieldlabel>qmd_questiontype</fieldlabel>
<fieldentry>Arithmetic</fieldentry>
</qti_metadatafield>
<qti_metadatafield>
<fieldlabel>qmd_weighting</fieldlabel>
<fieldentry>1.0000</fieldentry>
</qti_metadatafield>
</qtimetadata>
</itemmetadata>
<itemproc_extension>
<d2l_2p0:difficulty>1</d2l_2p0:difficulty>
<d2l_2p0:isbonus>no</d2l_2p0:isbonus>
<d2l_2p0:ismandatory>no</d2l_2p0:ismandatory>
</itemproc_extension>
<presentation>
<flow>
<material>
<mattext texttype="text/html"><![CDATA[<span style="font-family:'Arial';">What is the square of 6? <br>
<br>
NOTE: type in {a} then delete in respondus </span>]]></mattext>

<mat_extension>
<variable name="a">
<minvalue>0</minvalue>
<maxvalue>10</maxvalue>
<decimalplaces>0</decimalplaces>
<step>1</step>
</variable>
<formula>(36*({a}^0))</formula>
</mat_extension>
</material>
<response_num ident="QUES_1005_NUM" rcardinality="Single" rtiming="no">
<render_fib fibtype="Decimal" prompt="Box">
<response_label ident="QUES_1005_A1"/>
</render_fib>
</response_num>
<response_str ident="QUES_1005_STR" rcardinality="Single" rtiming="no">
<render_fib fibtype="String" prompt="Box">
<response_label ident="QUES_1005_A2"/>
</render_fib>
</response_str>
</flow>
</presentation>
<hint>
<hintmaterial>
<flow_mat>
<material>
<mattext texttype="text/plain" />
</material>
</flow_mat>
</hintmaterial>
</hint>
<resprocessing>
<respcondition title="Single Condition">
<respcond_extension>
<formula>(36*({a}^0))</formula>
<precision type="decimalplaces" d2l_2p0:precision_enforced="no">0</precision>
<tolerance type="units">0</tolerance>
<units d2l_2p0:worth="0" casesensitive="no" />
</respcond_extension>
<conditionvar>
<other />
</conditionvar>
<setvar action="Set">100</setvar>
</respcondition>
</resprocessing>
<itemfeedback ident="QUES_1005">
<material>
<mattext texttype="text/plain" />
</material>
</itemfeedback>
</item>

</section>
</objectbank>
</questestinterop>
Binary file not shown.
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:d2l_2p0="http://desire2learn.com/xsd/d2lcp_v2p0" xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" identifier="MANIFEST_1">
<resources>
<resource identifier="res_question_library" type="webcontent" d2l_2p0:material_type="d2lquestionlibrary" href="questiondb.xml"/>
</resources>
</manifest>

0 comments on commit 8f5461d

Please sign in to comment.