Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
2# encoding: utf-8
3"""
4*The model get for the `models_stats_get.py` resource*
6:Author:
7 David Young
8"""
9from future import standard_library
10standard_library.install_aliases()
11from builtins import object
12import sys
13import os
14import khufu
15import collections
16import urllib.request
17import urllib.parse
18import urllib.error
19import re
20from dryxPyramid.models.models_base import base_model
23class models_stats_get(base_model):
24 """
25 *The worker class for the models_stats_get module*
27 **Key Arguments**
29 - ``log`` -- logger
30 - ``request`` -- the pyramid request
31 - ``elementId`` -- the specific element id requests (or False)
33 **Usage**
35 ```python
36 usage code
37 ```
39 ```eval_rst
40 .. todo::
42 - add usage info
43 - create a sublime snippet for usage
44 - add a tutorial about ``models_stats_get`` to documentation
45 - create a blog post about what ``models_stats_get`` does
46 ```
47 """
49 def __init__(self, log, request, elementId=False, search=False):
50 super().__init__(log, request, elementId, search)
51 self.resourceName = "stats"
52 self._set_default_parameters()
54 log.debug(
55 "instansiating a new 'models_stats_get' object")
57 # Initial Actions
59 return None
61 def get(self):
62 """
63 *execute the get method on the models_stats_get object*
65 **Return**
67 - ``responseContent`` -- the reponse to send to the browser
69 """
70 self.log.debug('starting the ``get`` method')
72 elementId = self.elementId
73 # STATS OVERVIEW
74 sqlQuery = """
75 select * from stats_%(elementId)s_overview
76 """ % locals()
77 rowsTmp = self.request.db.execute(sqlQuery).fetchall()
79 fileTypes = []
80 fileTypes[:] = [dict(zip(row.keys(), row)) for row in rowsTmp]
82 for row in fileTypes:
83 try:
84 del row['primaryId']
85 except:
86 pass
88 sqlQuery = """
89 select sum(numberOfFiles) as numberOfFiles, sum(dataVolumeBytes) as dataVolumeBytes from stats_%(elementId)s_overview
90 """ % locals()
92 rowsTmp = self.request.db.execute(sqlQuery).fetchall()
93 fileTotals = []
94 fileTotals[:] = [dict(zip(row.keys(), row)) for row in rowsTmp]
96 if self.qs["format"] in ("csv", "plain_table"):
97 return fileTypes
99 self.log.debug('completed the ``get`` method')
100 return {"fileTypes": fileTypes, "fileTotals": fileTotals}
102 # xt-class-method