Exemple #1
0
def update_data():
  params = request.get_json()
  try:
    problem = sn.read_problem_json(params['schedules'])
    if 'working_file' in params:
      problem.save(params['working_file'])
    else:
      problem.save(tempfile.gettempdir() + '/' + 'schedule_problem')
    return Response(problem.tojson(),mimetype='application/json')

  except sn.RequirementException as e:
    if 'working_file' in params and os.path.isfile(params['working_file']):
      problem = sn.read_problem(params['working_file'])
    else:
      problem = sn.read_problem(tempfile.gettempdir() + '/' + 'schedule_problem')

    obj = problem.tojson(ammend={'unsatisfiable_meeting': e.mids[e.mindex]})
    return Response(obj,mimetype='application/json')
  except sn.AvailableTimesException as e:
    if 'working_file' in params and os.path.isfile(params['working_file']):
      problem = sn.read_problem(params['working_file'])
    else:
      problem = sn.read_problem(tempfile.gettempdir() + '/' + 'schedule_problem')

    obj = problem.tojson(ammend={'not_enough_times_agent': e.agents[e.aindex]})
    return Response(obj,mimetype='application/json')
Exemple #2
0
def request_data():
  params = request.get_json()
  if 'newfile' in params:
    return Response(sn.FastScheduleProblem().tojson())
  elif os.path.isfile(params['file']):
    return Response(sn.read_problem(params['file']).tojson(),
                    mimetype='application/json')
  else:
    return jsonify(nofile=True)