~xavierb

Secondary Teacher of Mathematics

#Contact

Trackers

~xavierb/automath

Last active 3 months ago

~xavierb/candoc-tasques

Last active 7 months ago

#5 Select template system library 21 days ago

Comment by ~xavierb on ~xavierb/automath

Now, we use ERB

#1 Deciding programming language 21 days ago

Comment by ~xavierb on ~xavierb/automath

Pass from python to ruby

REPORTED RESOLVED CLOSED

#1 Deciding programming language 24 days ago

Comment 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.

#1 Deciding programming language 25 days ago

critical added by ~xavierb on ~xavierb/automath

#1 Deciding programming language 25 days ago

Comment by ~xavierb on ~xavierb/automath

Perhaps ruby is more suitable, because it has ERB in default library.

RESOLVED CLOSED REPORTED

#6 Decide which language using in exercises 3 months ago

Comment by ~xavierb on ~xavierb/automath

One possibility is to put format field in AutomaticExercise class

#5 Select template system library 3 months ago

Comment by ~xavierb on ~xavierb/automath

We use jinja2

REPORTED RESOLVED CLOSED

#5 Select template system library 3 months ago

Comment 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'}

#5 Select template system library 3 months ago

Comment by ~xavierb on ~xavierb/automath

There is no ideal template, like ERB in ruby, which having all we need. We have to prioritze what we want.

#5 Select template system library 3 months ago

Comment by ~xavierb on ~xavierb/automath

RESOLVED CLOSED REPORTED