import pandas as pd
from pandas.io.json import json_normalize
import json

import nback, generic

class NBackPreprocessingPipeline():
  def __init__(self, json_path):
    self.json_path = json_path
    super().__init__()
  
  def run(self):
    with open(self.json_path) as f:
      js_data = json.load(f)
      data = json_normalize(js_data,record_prefix=False,max_level=1)

      data = data.pipe(nback.extract_events). \
                  pipe(generic.filter_instructions)
      return data

  def __repr__(self):
    return "Sample JSON"

if __name__ == "__main__":

  json_file = "data/samples/nback_demo_v.json"
  print(NBackPreprocessingPipeline(json_file).run())