Jinja2 cannot understand formats on Raspberry Pi

I am trying to run a basic reporting tool from the Raspberry Pi on my internal network. For this I use:

  • Raspbian OS
  • Flask (Jinja2)
  • Pandas to fetch cached values ​​from SQLite db (via pandas.io)
  • Numpy, for data aggregation.

Basically, I have a Flask view that pulls some daily totals (date, visits, video games, etc.) from a SQLite table and then aggregates the data by date via NumPy, converts it to a tuple, and then kicks in this HTML template ... In my HTML template, I have a Jinja filter that converts dates to a friendlier format and then converts any numbers to comma separated format for easier reading.

Worked fine on my temporary staging environment (my own laptop is OSX 10.9.5). But running it on a Raspberry Pi - either remotely via ssh or directly from the Pi-Jinja2 suddenly forgets how to deal with the numbers. On creation, Jinja2 treats numpy.int64 types as a number. On the Raspberry Pi, it acts like an unknown format.

Here is the code I am using to convert a pandas array to a tuple:

data_set = [tuple(x) for x in grand_total.to_records(index = False)]

      

And here is a Jinja template filter that I am using to handle dates. I added an extra elif to convert numpy.int64 to int in there, but it still doesn't work.

@app.template_filter('DateFormattr')
def DateFormattr(PossDate):
  if(isinstance(PossDate, numpy.datetime64)):
    PossDate = pandas.to_datetime(PossDate)
    PossDate.date().strftime('%Y-%m-%d')
    PossDate = str(PossDate)[0:10]
    return PossDate
  else:
    return PossDate

      

And here is the code to create the actual table:

{% for row in the_data %}

<tr>
{% for cell in row %}
 <td> 
  {% if cell is not number  %}
    <b>
    {{ cell | DateFormattr }}
    </b>
  {% else %}
    {% print '{0:,}'.format(cell | int) %}
  {% endif %}
  </td>

      

What's going on here? Is there a quirk on the Raspberry Pi that makes Flask or Jinja2 struggle to move?

There's a lot going on there, and I may have missed some details, so feel free to ask for more clarification.

Edited to add Relevant packages:

On RPi:

  • Flask 0.10.1
  • Flask-WTF 0.11
  • WTForms 2.0.2
  • Jinja2 2.7.3
  • numpy 1.8.2
  • Pandas 0.14.1
  • SQLAlchemy 1.0.4

On Mac:

  • Flask 0.10.1
  • Flask-WTF 0.11
  • WTForms 2.0.2
  • Jinja2 2.7.3
  • numpy 1.9.2
  • Pandas 0.15.2
  • SQLAlchemy 0.9.9

Both run Python v2.7.9. (Someday I will stop worrying and learn to love Python 3.)

IIRC, I had to use apt-get to install pandas due to RPi limitations, hence the version differences.

+3


source to share





All Articles