Browse Source

for homecuda dev

stanley-king 2 years atrás
parent
commit
bb3a972278

+ 9 - 22
plot/mprofit_ratio.py

@@ -1,32 +1,19 @@
-
-from refill import MerchantCalc
+from refill import opt_parse,MProfitRatioCalc
 import signal as sig
-import sys,getopt
-
 import logging
+
 logging.basicConfig(filename='/var/www/html/data/log/statcalc.log',
                     format='%(levelname)10s  %(asctime)s  %(name)10s %(thread)d %(message)s',
                     level=logging.DEBUG)
 
+log = logging.getLogger('profit_ratio')
 
 if __name__ == '__main__':
     try:
-        opts, args = getopt.getopt(sys.argv[1:], "h:p:", ["host=", 'port='])
+        rhost, rhost = opt_parse()
+        calc = MProfitRatioCalc()
+        calc.set_redis(rhost,rport)
+        sig.signal(sig.SIGINT, lambda: calc.stop())
+        calc.run()
     except Exception as ex:
-        print(ex)
-        sys.exit(2)
-
-    rhost = ''
-    rport=6379
-    for o, val in opts:
-        if o in ("-h", "--host"):
-            rhost = val
-        elif o in ('-p', "--port"):
-            rport = int(val)
-        else:
-            print("Err argv")
-
-    calc = MerchantCalc()
-    calc.set_redis(rhost,rport)
-    sig.signal(sig.SIGINT, lambda: calc.stop())
-    calc.run()
+        log.error(ex)

+ 4 - 2
plot/refill/CalcBase.py

@@ -13,6 +13,9 @@ class CalcBase(object):
         self._mRHost = rhost
         self._mRPort = rport
 
+    def stop(self):
+        self._mquit = True
+
     def _calc_handler(self, rclient):
         pass
 
@@ -57,5 +60,4 @@ class CalcBase(object):
         sdays = [strtime(day) for day in days]
         logger.debug(sdays)
 
-        return days, start_time, end_time
-        pass
+        return days, start_time, end_time

+ 3 - 2
plot/refill/MProfitRatioCalc.py

@@ -1,6 +1,7 @@
-from .CalcBase import CalcBase
+from .CalcBase import CalcBas
+from .MerchantCalcBase import MerchantCalcBase
 
 
-class MProfitRatioCalc(CalcBase):
+class MProfitRatioCalc(MerchantCalcBase):
     def _calc_handler(self, rclient):
         pass

+ 2 - 1
plot/refill/__init__.py

@@ -12,6 +12,7 @@ from .ChannelPainter import ChannelPainter,get_channels
 from .MerchantPainter import MerchantPainter,get_mchids
 from .helper import filter_chname, filter_cardtype, filter_mchids
 from .MerchantCalc import MerchantCalc
+from .MProfitRatioCalc import MProfitRatioCalc
 from .WriterConsumer import WriterConsumer
 from .server_util import opt_parse
 
@@ -21,5 +22,5 @@ __all__ = ['DataWriteStream', 'DataReadStream',
            'ChannelPainter', 'MerchantPainter', 'get_channels', 'get_mchids',
            'queueListener', 'open_hdf5', 'day_stamp', 'time_border',
            'filter_chname', 'filter_cardtype', 'filter_mchids',
-           'MerchantCalc',
+           'MerchantCalc','MProfitRatioCalc'
            'opt_parse']

+ 3 - 0
plot/refill/server_util.py

@@ -1,4 +1,7 @@
+import sys, getopt
+
 def opt_parse():
+    x = sys.argv
     opts, args = getopt.getopt(sys.argv[1:], "h:p:", ["host=", 'port='])
     rhost = ''
     rport = 6379