Skip to content

Commit

Permalink
Added the query for listing companies
Browse files Browse the repository at this point in the history
  • Loading branch information
Vullkan92 committed Jan 21, 2015
1 parent 75b6d02 commit 21c751d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
6 changes: 6 additions & 0 deletions mcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def configure_logging(app):
from views.treemapprice import TreemapPrice
from views.vlera_cmimi import VleraCmimi
from views.municipalityPV import MunicipalityList
from views.company_names import CompanyNames




Expand Down Expand Up @@ -154,6 +156,10 @@ def register_url_rules(app):
app.add_url_rule(
'/monthly-summary/<int:viti>', view_func=cached_municipality)

cached_company_names = app.cache.cached()(CompanyNames.as_view('json_company_names'))
app.add_url_rule(
'/<string:komuna>/company-names/<int:viti>', view_func=cached_company_names)

cached_pie = app.cache.cached()(Piechart.as_view('json_pie'))
app.add_url_rule(
'/<string:komuna>/piechart/<int:viti>', view_func=cached_pie)
Expand Down
1 change: 1 addition & 0 deletions mcp/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Beni nje GET request ne lidhjet e meposhtme.</h1>
<p>http://0.0.0.0:porti/<b>string:komuna</b>/piechart/<b>int:year</b><p>
<p>http://0.0.0.0:porti/<b>string:komuna</b>/treemap/<b>int:year</b><p>
<p>http://0.0.0.0:porti/<b>string:komuna</b>/monthly-summary/<b>int:year</b><p>
<p>http://0.0.0.0:porti/monthly-summary/<b>int:year</b><p>

</body>
</html>
60 changes: 60 additions & 0 deletions mcp/views/company_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from flask import Response
from flask.views import View
from bson import json_util
from mcp import mongo


class CompanyNames(View):
#@app.route("/<string:komuna>/monthly-summary")
def dispatch_request(self, viti, komuna):
json = mongo.db.procurements.aggregate([
{
"$match": {
"viti": viti,
"city": komuna
}
},
{
"$group": {
'_id': {
'kompania_emri': '$kompania.emri',
"aktiviteti": "$aktiviteti",
'muaji': {
'$month': '$dataNenshkrimit'
}
},
"vlera": {
"$sum": "$kontrata.vlera"
},
"qmimi": {
"$sum": "$kontrata.qmimi"
},
"qmimiAneks": {
"$sum": "$kontrata.qmimiAneks"
}
},
},
{
'$sort': {
'muaji': -1
}
},
{
"$project": {
"_id": 0,
"pershkrimi": "$_id.aktiviteti",
"kompania": "$_id.kompania_emri",
"vlera": "$vlera",
"qmimi": "$qmimi",
"qmimiAneks": "$qmimiAneks",
}
}
])

#pergjigjen e kthyer dhe te konvertuar ne JSON ne baze te json_util.dumps() e ruajme ne resp
resp = Response(
response=json_util.dumps(json['result']),
mimetype='application/json')

#ne momentin kur hapim sh.: http://127.0.0.1:5000/treemap duhet te kthejme JSON, ne rastin tone resp.
return resp
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Create the flask app.
app = create_app()

# Run the app
if __name__ == '__main__':

Expand Down

0 comments on commit 21c751d

Please sign in to comment.