"""
This script was run to generate the resolution study. it requres the generated
sqlite3 db of results from the gmsh folder.
"""


import sys
import sqlite3
import numpy as np

from interp.tools import rms

con = sqlite3.connect(sys.argv[1])
cur = con.cursor()

orders = np.array(cur.execute('select distinct ord from results').fetchall())[:,0]
eps    = np.array(cur.execute('select distinct ep  from results').fetchall())[:,0]
res    = np.array(cur.execute('select distinct res from results').fetchall())[:,0]

params = (
           (2,64),
           (3,64),
           (4,64),
           (5,64),
         )
for r in res:
  for order, ep in params:
    # print np.array([np.abs(i[FINAL] - i[EXACT]) for i in data if i[ORDER] == order and i[EP] == ep])),
    cur_results = cur.execute('select abs(exact - final) from results where res = ? and ep = ? and ord = ?',
                             (int(r), int(ep),int(order)))
    cur_ = np.array(cur_results.fetchall())
    print rms(np.array(cur_)),
  print
