Hide keyboard shortcuts

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* 

5 

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 

21 

22 

23class models_stats_get(base_model): 

24 """ 

25 *The worker class for the models_stats_get module* 

26 

27 **Key Arguments** 

28 

29 - ``log`` -- logger 

30 - ``request`` -- the pyramid request 

31 - ``elementId`` -- the specific element id requests (or False) 

32 

33 **Usage** 

34 

35 ```python 

36 usage code  

37 ``` 

38 

39 ```eval_rst 

40 .. todo:: 

41 

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 """ 

48 

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() 

53 

54 log.debug( 

55 "instansiating a new 'models_stats_get' object") 

56 

57 # Initial Actions 

58 

59 return None 

60 

61 def get(self): 

62 """ 

63 *execute the get method on the models_stats_get object* 

64 

65 **Return** 

66 

67 - ``responseContent`` -- the reponse to send to the browser 

68 

69 """ 

70 self.log.debug('starting the ``get`` method') 

71 

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() 

78 

79 fileTypes = [] 

80 fileTypes[:] = [dict(zip(row.keys(), row)) for row in rowsTmp] 

81 

82 for row in fileTypes: 

83 try: 

84 del row['primaryId'] 

85 except: 

86 pass 

87 

88 sqlQuery = """ 

89 select sum(numberOfFiles) as numberOfFiles, sum(dataVolumeBytes) as dataVolumeBytes from stats_%(elementId)s_overview 

90 """ % locals() 

91 

92 rowsTmp = self.request.db.execute(sqlQuery).fetchall() 

93 fileTotals = [] 

94 fileTotals[:] = [dict(zip(row.keys(), row)) for row in rowsTmp] 

95 

96 if self.qs["format"] in ("csv", "plain_table"): 

97 return fileTypes 

98 

99 self.log.debug('completed the ``get`` method') 

100 return {"fileTypes": fileTypes, "fileTotals": fileTotals} 

101 

102 # xt-class-method