def index(page): page = page per_page = 10 professor = ProfessorIndexForm() professores = Professor.query professor.descricao.data = request.args.get('descricao') professor.inicio.data = parse_date( request.args.get('inicio')) if request.args.get('inicio') else '' professor.fim.data = parse_date( request.args.get('fim')) if request.args.get('fim') else '' professores = professores.filter( Professor.descricao.ilike(sql_ilike_format(professor.descricao.data)) ) if professor.descricao.data else professores professores = professores.filter( Professor.vencimento >= sql_date_format(professor.inicio.data) ) if professor.inicio.data else professores professores = professores.filter( Professor.vencimento <= sql_date_format(professor.fim.data) ) if professor.fim.data else professores professores = professores.order_by(Professor.codigo.desc()).paginate( page, per_page=per_page, error_out=True) return render_template('professores/index.html', professores=professores, titulo_form=professor)
def get_attractions_aggregate(request): """ Get average wait time of attractions --- nickname: AttractionsAggregate parameters: - name: startdate type: string in: query format: date-time - name: enddate format: date-time in: query type: string - name: attractions in: query type: array """ attractionsParam = request.GET.get('attractions') if ',' in attractionsParam: myListAttractions = attractionsParam.split(',') else: myListAttractions = request.GET.getlist('attractions') start_date = parse_date(request.GET.get('startdate')) end_date = parse_date(request.GET.get('enddate')) docs = AttractionsDao.find_aggregate_attractions_between_date(myListAttractions,start_date, end_date) serializer = AggregateAttractionSerialize(data = docs, many=True) if serializer.is_valid(): return Response(serializer.validated_data, status=status.HTTP_200_OK) else: return Response(status=status.HTTP_400_BAD_REQUEST)
def index(page): page = page per_page = 10 disciplina = DisciplinaIndexForm() disciplinas = Disciplina.query disciplina.descricao.data = request.args.get('descricao') disciplina.inicio.data = parse_date( request.args.get('inicio')) if request.args.get('inicio') else '' disciplina.fim.data = parse_date( request.args.get('fim')) if request.args.get('fim') else '' disciplinas = disciplinas.filter( Disciplina.descricao.ilike(sql_ilike_format(disciplina.descricao.data)) ) if disciplina.descricao.data else disciplinas disciplinas = disciplinas.filter( Disciplina.vencimento >= sql_date_format(disciplina.inicio.data) ) if disciplina.inicio.data else disciplinas disciplinas = disciplinas.filter( Disciplina.vencimento <= sql_date_format(disciplina.fim.data) ) if disciplina.fim.data else disciplinas disciplinas = disciplinas.order_by(Disciplina.codigo.desc()).paginate( page, per_page=per_page, error_out=True) return render_template('disciplinas/index.html', disciplinas=disciplinas, titulo_form=disciplina)
def create_submission(self, user, assignment, messages, submit, submitter): """ Create submission using user as parent to ensure ordering. :param user: (object) caller :param assignment: (Assignment) :param messages: Data content of backup/submission :param submit: Whether this backup is a submission to be graded :param submitter: (object) caller or submitter :return: (Backup) submission """ if not user.is_admin or not submitter: submitter = user.key message_date = None analytics = messages.get('analytics') if analytics: message_date = analytics.get('time', None) if message_date: created = parse_date(message_date) else: created = datetime.datetime.now() ms = lambda kind, message: models.Message(kind=kind, contents=message) db_messages = [ms(k, m) for k, m in messages.iteritems() if m] backup = models.Backup(submitter=submitter, assignment=assignment.key, messages=db_messages, created=created) backup.put() deferred.defer(assign_submission, backup.key.id(), submit) return backup
def create_submission(self, user, assignment, messages, submit, submitter): """Create submission using user as parent to ensure ordering.""" if not user.is_admin: submitter = user.key # TODO - Choose member of group if the user is an admin. db_messages = [] for kind, message in messages.iteritems(): if message: db_messages.append(models.Message(kind=kind, contents=message)) created = datetime.datetime.now() if messages.get('analytics'): date = messages['analytics']['time'] if date: created = parse_date(date) submission = models.Submission(submitter=submitter, assignment=assignment.key, messages=db_messages, created=created) submission.put() deferred.defer(assign_submission, submission.key.id()) return submission
def prepare_data(cls, array): if len(array) != cls.NUMBER_OF_COLUMNS: raise MinerError('wrong number of columns') array[2] = parse_date(array[2]) array[-3] = locale.atoi(array[-3]) array[-2] = locale.atof(array[-2]) array[-1] = locale.atoi(array[-1])
def index(page): page = page per_page = 10 curso = CursoIndexForm() cursos = Curso.query curso.descricao.data = request.args.get('descricao') curso.inicio.data = parse_date(request.args.get('inicio')) if request.args.get('inicio') else '' curso.fim.data = parse_date(request.args.get('fim')) if request.args.get('fim') else '' cursos = cursos.filter( Curso.descricao.ilike(sql_ilike_format(curso.descricao.data)) ) if curso.descricao.data else cursos cursos = cursos.filter( Curso.vencimento >= sql_date_format(curso.inicio.data) ) if curso.inicio.data else cursos cursos = cursos.filter( Curso.vencimento <= sql_date_format(curso.fim.data) ) if curso.fim.data else cursos cursos = cursos.order_by(Curso.codigo.desc()).paginate(page, per_page=per_page, error_out=True) return render_template('cursos/index.html', cursos=cursos, titulo_form=curso)
def upgrade(self): created = self.created analytics = self.messages.get('analytics') if analytics: date = analytics.get('time') or created if not date == created: created = parse_date(date) new_messages = [Message(kind=kind, contents=contents) for kind, contents in self.messages.iteritems()] return Submission( submitter=self.submitter, assignment=self.assignment, created=created, messages=new_messages)
def get_single_line_chart_hist(json, is_new_stats): stats = defaultdict(lambda: defaultdict(list)) for stats_type in json: last_value = 0 for date in json[stats_type]: date_obj = utils.parse_date(date) date_str = utils.format_date(date_obj) stats[stats_type]["labels"].append(date_str) stats[stats_type]["total"] = json[stats_type][date] curr_value = json[stats_type][date] if is_new_stats: new_value = curr_value - last_value last_value = curr_value else: new_value = curr_value stats[stats_type]["data"].append(new_value) return stats
def analytics(request, tick, is_json_response): try: date_from = parse_date(request.GET['date_from']) date_to = parse_date(request.GET['date_to']) except KeyError: raise Http404 qs = Trade.objects.filter(company__code=tick, date__range=(date_from, date_to)).order_by('-date') open_price_list, high_price_list, low_price_list, close_price_list, date_list = zip( *qs.values_list('open_price', 'high_price', 'low_price', 'close_price', 'date')) prises = [ open_price_list, high_price_list, low_price_list, close_price_list, ] new_data = [ map(lambda x: round(x[0] - x[1], 2), pairwise(d)) for d in prises ] new_data = zip(date_list[:-1], *new_data) if is_json_response: return JsonResponse({ 'analytics': [{ 'date': trade_date, 'open_delta': open_delta, 'high_delta': high_delta, 'low_delta': low_delta, 'close_delta': close_delta } for trade_date, open_delta, high_delta, low_delta, close_delta in new_data] }) context = { 'date_from': date_from, 'date_to': date_to, 'tick': tick, 'open_price_list': json.dumps(open_price_list), 'high_price_list': json.dumps(high_price_list), 'low_price_list': json.dumps(low_price_list), 'close_price_list': json.dumps(close_price_list), 'date_list': json.dumps( tuple(map(lambda date: date.strftime('%Y-%m-%d'), date_list))), 'range': qs.aggregate(Max('high_price'), Min('low_price')), 'new_data': new_data, } return TemplateResponse(request, 'app/analytics.html', context)