GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6fb05a...f18c8f )
by Alex
02:08
created

summary()   B

Complexity

Conditions 2

Size

Total Lines 30

Duplication

Lines 30
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 30
loc 30
rs 8.8571
1
from flask import Blueprint, jsonify
2
from sqlalchemy import JSON, func
3
4
from sugarloaf.models import db, TrailStatus, Trail, Area
5
6
api = Blueprint('api', __name__)
7
8 View Code Duplication
@api.route('/current')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
def current():
10
    """Return a json with most recent trail and lift conditions and daily report"""
11
    latest = db.session.scalar(func.MAX(TrailStatus.dt))
12
13
    trails = db.session.query(Trail.name, 
14
                              Trail.difficulty,
15
                              Area.name.label('area'), 
16
                              TrailStatus.open,
17
                              TrailStatus.groomed,
18
                              TrailStatus.snowmaking,
19
                              )\
20
                       .filter(TrailStatus.trail_id == Trail.id,
21
                               Area.id == Trail.area_id,
22
                               TrailStatus.dt == latest)
23
24
    return jsonify(
25
        {'trails': [{'name': trail.name,
26
                     'difficulty': trail.difficulty,
27
                     'area': trail.area,
28
                     'groomed': trail.groomed,
29
                     'snowmaking': trail.snowmaking,
30
                     'open': trail.open} for trail in trails]})
31
32
33 View Code Duplication
@api.route('/summary')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
34
def summary():
35
    """ Return json with a summary of the trail status by update """
36
    conditions = db.session.query(TrailStatus.dt, 
37
                                  TrailStatus.open, 
38
                                  TrailStatus.groomed, 
39
                                  TrailStatus.snowmaking, 
40
                                  Trail.difficulty, 
41
                                  Area.name,
42
                                  func.count())\
43
                            .filter(TrailStatus.trail_id == Trail.id, Trail.area_id == Area.id)\
44
                            .group_by(TrailStatus.dt, 
45
                                      TrailStatus.open, 
46
                                      TrailStatus.groomed, 
47
                                      TrailStatus.snowmaking, 
48
                                      Trail.difficulty,
49
                                      Area.name)
50
51
    output = {'conditions': [{
52
            'datetime': condition.dt,
53
            'open': condition.open,
54
            'groomed': condition.groomed,
55
            'snowmaking': condition.snowmaking,
56
            'difficulty': condition.difficulty,
57
            'trail_count': condition[5],
58
            'area': condition.name
59
        } for condition in conditions]}
60
61
    print(output)
62
    return jsonify(output)