Secondary Teacher of Mathematics
Comment by ~xavierb on ~xavierb/automath
Now, we use ERB
Comment by ~xavierb on ~xavierb/automath
Pass from python to ruby
REPORTED
RESOLVED CLOSEDComment by ~xavierb on ~xavierb/automath
Very easy with ruby:
require 'erb' class AutomaticExercise attr_accessor :info def initialize(info) @info = info end def conditions if @info.has_key?(:conditions) return @info[:conditions] else return nil end end def satisfied_conditions(assignments) return eval(ERB.new(self.conditions).result_with_hash(assignments)) end def numeric_value(assignments) if self.conditions != nil if self.satisfied_conditions(assignments) != true return nil end end r = Hash.new @info.keys.each do |k| r[k] = ERB.new(@info[k]).result_with_hash(assignments) end return r end end e = AutomaticExercise.new({:text => "Sum <%=a%>+<%=b%>", :solution => "<%=a+b%>", :conditions => "<%=a%> > 0"}) puts e.conditions.class puts e.info puts e.satisfied_conditions({:a => 5}) puts e.satisfied_conditions({:a => -1}) puts e.numeric_value({:a => 2, :b=>3}) puts e.numeric_value({:a => -1, :b=>3})
We avoid complexity of jinja templates. ERB is easy.
Comment by ~xavierb on ~xavierb/automath
Perhaps ruby is more suitable, because it has ERB in default library.
RESOLVED CLOSED
REPORTEDComment by ~xavierb on ~xavierb/automath
One possibility is to put
format
field inAutomaticExercise
class
Comment by ~xavierb on ~xavierb/automath
We use jinja2
REPORTED
RESOLVED CLOSEDComment by ~xavierb on ~xavierb/automath
With jinja2:
import automathlib import fractions e.NumericValue({'a': fractions.Fraction(1,2), 'b': 3}) {'text': 'Calculate the sum of 1/2 and 3', 'solution': '7/2', 'resolution': '7/2'}