Example #1
0
    def __init__(self, dbPath, dbName):
        self.database = dbPath + dbName
        self.dataPath = dbPath
        self.visits = Visits()
        self.guests = Guests()
        self.reports = Reports(self)
        self.teams = Teams()
        self.accounts = Accounts()
        self.devices = Devices()
        self.unlocks = Unlocks()
        # needs path since it will open read only
        self.customReports = CustomReports(self.database)
        self.certifications = Certifications()
        self.members = Members()
        self.logEvents = LogEvents()

        if not os.path.exists(self.database):
            if not os.path.exists(dbPath):
                os.mkdir(dbPath)
            with self.dbConnect() as c:
                self.migrate(c, 0)
        else:
            with self.dbConnect() as c:
                data = c.execute('PRAGMA schema_version').fetchone()
                if data[0] != SCHEMA_VERSION:
                    self.migrate(c, data[0])
Example #2
0
 def create_wallet(cls, user_id: str) -> bool:
     "A method to initialize a users wallet"
     if not user_id in cls._wallets:
         cls._wallets[user_id] = Decimal('0')
         Reports.log_event(f"wallet for `{user_id}` created and set to 0")
         return True
     return False
    def generate_reports(self):
        """ After all scan files are parsed, begin generating Excel Tabs """
        logging.info('Generating Reports')

        reports = Reports(main_app.main_window)

        total_reports = list(
            filter(lambda x: x.startswith('rpt'), dir(reports)))
        index = 0
        for report in total_reports:
            index += 1
            status = f"Generating Report {report}"
            print(status)
            logging.info(status)

            if main_app.main_window:
                main_app.main_window.progressBar.setValue(
                    int(100 * index / (len(total_reports)) * .9))
                QtGui.QGuiApplication.processEvents()
            getattr(reports, report)()

        reports.close_workbook()

        status = f"Report Generated"
        logging.info(status)
        print(status)
        if main_app.main_window:
            main_app.main_window.statusBar().showMessage(status)
            main_app.main_window.progressBar.setValue(0)
            QtGui.QGuiApplication.processEvents()
 def register_user(cls, new_user: dict[str, str]) -> str:
     "register a user"
     if not new_user["user_name"] in cls._users:
         # generate really complicated unique user_id.
         # Using the existing user_name as the id for simplicity
         user_id = new_user["user_name"]
         cls._users[user_id] = new_user
         Reports.log_event(f"new user `{user_id}` created")
         # create a wallet for the new user
         Wallets().create_wallet(user_id)
         # give the user a sign up bonus
         Reports.log_event(f"Give new user `{user_id}` sign up bonus of 10")
         Wallets().adjust_balance(user_id, Decimal(10))
         return user_id
     return ""
Example #5
0
    def generate_reports(self):
        """ After all scan files are parsed, begin generating Excel Tabs """

        reports = Reports(self.scan_results, self.data_mapping,
                          self.contact_info, self.poam_conf,
                          S2R.scans_to_reports)

        for report in filter(lambda x: x.startswith('rpt'), dir(reports)):
            print(report)
            getattr(reports, report)()
            QtWidgets.QApplication.processEvents()

        reports.close()
        if S2R.scans_to_reports:
            S2R.scans_to_reports.statusBar().showMessage("Report Generated")
Example #6
0
 def __init__(self, chat_id, bot ):
     conn = sqlite3.connect(dataBaseDjangoDir)
     cursor = conn.cursor()
     cursor.execute("""select * from usuarios_usuario""")
     conn.commit()
     query = (cursor.fetchall())
     for user in query:
         if user[4] == chat_id:
             self.name = user[1]
             self.email = user[4]
             self.authorize = True
             self.help = Help(chat_id)
             self.sensiTags = SensiTags(bot)
             self.graphic = Graphics()
             self.report = Reports()
     self.chat_id = chat_id
Example #7
0
    def GET(self):
        web.header('Content-Type', 'text/html;charset=UTF-8')
        form = web.input(email="*****@*****.**",
                         campaignId=None,
                         starttime=None,
                         endtime=None)

        logger.info("Received user " + form.email +
                    " request to get campaign report")

        httpsSession = createHttpsSession(form.email)
        reportsPath = cf.get("apiservices", "reports")
        reporthandler = Reports(reportsPath, httpsSession, logger)

        result = reporthandler.query_all_campaigns(email=form.email,
                                                   campaignId=form.campaignId,
                                                   starttime=form.starttime,
                                                   endtime=form.endtime)

        return result
Example #8
0
 def submit_entry(cls, user_id: str, entry: Decimal) -> bool:
     "Submit a new entry for the user in this game"
     now = int(time.time())
     time_remaining = cls._start_time - now + cls._clock
     if time_remaining > 0:
         if Wallets.get_balance(user_id) > Decimal('1'):
             if Wallets.adjust_balance(user_id, Decimal('-1')):
                 cls._entries.append((user_id, entry))
                 Reports.log_event(
                     f"New entry `{entry}` submitted by `{user_id}`")
                 return True
             Reports.log_event(
                 f"Problem adjusting balance for `{user_id}`")
             return False
         Reports.log_event(f"User Balance for `{user_id}` to low")
         return False
     Reports.log_event("Game Closed")
     return False
Example #9
0
def report_excel(request):
    log_start_time = datetime.utcnow()
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/ui/login/?next=/ui/')
        
    log_entry = LogEntry()
    log_entry.user = request.user
    log_entry.timestamp = log_start_time
    log_entry.post_data = request.POST
    
    if request.POST.has_key('chkReporter') \
        and request.POST.has_key('hdnResultType') \
        and request.POST.has_key('txtStartDate') \
        and request.POST.has_key('txtEndDate'):
        
        start_date = request.POST.get('txtStartDate')
        end_date = request.POST.get('txtEndDate')
        reporters = request.POST.get('chkReporter').split(',')
        reporter_type = request.POST.get('hdnResultType')

    else:
        return HttpResponse('insufficient parameters')
                
    filename = 'wqm_reporters_%s_%s.xls' % (start_date, end_date)
    
    if reporter_type == 'NAME':
        samples = Sample.objects.filter(reporter_name__in=reporters, date_taken__gte=start_date, date_taken__lte=end_date).order_by('date_taken')
        log_entry.event_type = 'rep_reporter_name'
    elif reporter_type == 'TEL':
        samples = Sample.objects.filter(taken_by__connections__identity__in=reporters, date_taken__gte=start_date, date_taken__lte=end_date).order_by('date_taken')
        log_entry.event_type = 'rep_reporter_tel'
    else:
        return HttpResponse('Unknown reporter type supplied')
    
    # Create the HttpResponse object with the appropriate XLS header info.
    response = HttpResponse(mimetype="application/ms-excel")
    response['Content-Disposition'] = 'attachment; filename=%s' % filename
    
    wb = Reports.get_basic_for_samples(samples)
    wb.save(response)
    
    log_entry.set_processing_time(log_start_time)
    log_entry.save()
    
    return response
Example #10
0
 def reports_btn(self):
     root2 = Toplevel(self.master)
     myGui = Reports(root2)
Example #11
0
    async def _get_html(self, speed=1):
        """
        :param speed: 翻页间隔时间,秒
        :return: 返回爬取页面的HTML内容
        """
        sql = "select shop_id from shop_info where shop_id!='88888888'"  # 获取所有的店铺ID
        shop_infos = mysql.get_data(sql=sql, dict_result=True)
        shop_ids = []
        for shop_info in shop_infos:
            page_control = Format._read(shop_id=shop_info['shop_id'], flag="total_page")  # 获得存储在本地的店铺总的页码数量
            if not page_control:
                page_control = 1000  # 如果没有获取到页码总数,给个1000的总数

            shop_ids.append(shop_info['shop_id'])  # 将店铺ID存储起来用于后面重置翻页数据

            url = self.start_url.replace("shop", "shop" + shop_info["shop_id"])  # 获得到店铺首页url地址
            await self.page.goto(url)
            await self._jump_to_search_page()
            page_num = Format._read(shop_info['shop_id'], "page_num")  # 读取存储在本地的page_num

            while page_num < page_control:
                start_time = time.time()  # 本页面开始的时间存入变量

                try:
                    # if page_num:
                    await self._goto_last_page_num(page_num + 1)
                    await asyncio.sleep(5)
                    frames = self.page.frames
                    for f in frames:
                        if await f.J("#TPL_username_1"):
                            yield 0, 0
                    frame = await self.login.get_nc_frame(frames=frames)
                    if frame:
                        await self.login.slider(self.page, 1)

                except Exception as e:
                    print(e)
                    await asyncio.sleep(5)
                    continue
                try:
                    await self.page.waitForSelector(".shop-hesper-bd.grid")
                except errors.TimeoutError:
                    break
                except Exception as e:
                    print(e)
                    continue
                Format._write(shop_id=shop_info['shop_id'], flag="page_num", value=page_num + 1)  # 将下次需要爬取的页码存入本地的配件中
                page_num = Format._read(shop_info['shop_id'], "page_num")  # 读取下一次要爬取的页码

                yield await self.page.content(), shop_info['shop_id']  # 返回页面HTML内容和

                page_control = Format._read(shop_id=shop_info['shop_id'], flag="total_page")  # 获得存储在本地的店铺总的页码数量

                await asyncio.sleep(speed)  # 翻页间隔时间
                spent_time_this_page = time.time() - start_time  # 计算本页完成时间
                spent_time = Format._read(shop_id=shop_info['shop_id'], flag="spent_time")  # 读取上一次存储在本地的时间
                Format._write(shop_id=shop_info['shop_id'], flag="spent_time",
                              value=spent_time + spent_time_this_page)  # 将本页面完成时间加上后并存储在本地
            is_mail = Format._read(shop_info['shop_id'], "mail")
            if not is_mail:
                Reports().report(shop_info['shop_id'].split(" "))

        for shop_id in shop_ids:
            Format._del(shop_id=shop_id, flag="page_num")  # 重置翻页的数据
            Format._del(shop_id=shop_id, flag="total_page")  # 重置总页码数据
            Format._del(shop_id=shop_id, flag="mail")  # 重置邮件标记
            Format._del(shop_id=shop_id, flag="spent_time")  # 重置完成时间
Example #12
0
def report_preview(request, domain_id):
    log_start_time = datetime.utcnow()
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/ui/login/?next=/ui/')
    try:
        # attempt load up the requested domain if the user has access to it
        domain = Domain.objects.filter(  membership__member_type = ContentType.objects.get_for_model(User), 
                                                    membership__member_id = request.user.id, 
                                                    membership__is_active=True, # Looks in membership table
                                                    is_active=True,
                                                    id = domain_id)[0] # Looks in domain table
        
    except IndexError:
        # if it wasn't loaded it either doesn't exist (in which case the user is poking around with the url)
        # or the user doesn't have access to it. Either way, best to just display access denied so people
        # messing with URLs get as little info as possible.
        #TODO: redirect to an access denied page
        return HttpResponse('access denied - you don\'t have access to this domain id')
    
    log_entry = LogEntry()
    log_entry.user = request.user
    log_entry.timestamp = log_start_time
    log_entry.post_data = request.POST
    
    if request.POST.has_key('chkReporter') \
        and request.POST.has_key('hdnResultType') \
        and request.POST.has_key('txtStartDate') \
        and request.POST.has_key('txtEndDate'):
        
        start_date = request.POST.get('txtStartDate')
        end_date = request.POST.get('txtEndDate')
        reporters = request.POST.getlist('chkReporter')
        reporter_type = request.POST.get('hdnResultType')

    else:
        return HttpResponse('insufficient parameters')
                
    filename = 'wqm_reporters_%s_%s_%s.xls' % (domain.name.replace(' ', '_') .replace('\\','_').replace('//','_').replace('?','_').replace("'","_"),
                                 start_date,
                                 end_date)
    
    if reporter_type == 'NAME':
        samples = Sample.objects.filter(reporter_name__in=reporters, date_taken__gte=start_date, date_taken__lte=end_date).order_by('date_taken')
        log_entry.event_type = 'rep_prev_reporter_name'
    elif reporter_type == 'TEL':
        samples = Sample.objects.filter(taken_by__connections__identity__in=reporters, date_taken__gte=start_date, date_taken__lte=end_date).order_by('date_taken')
        log_entry.event_type = 'rep_prev_reporter_tel'
    else:
        return HttpResponse('Unknown reporter type supplied')
    
    report_html = Reports.get_report_html(samples)
    
    template = loader.get_template('ui-report-preview.html')
    context = Context({    'domain' : domain,
                        'user' : request.user,
                        'report_table' : report_html,
                        'start_date' : start_date,
                        'end_date' : end_date,
                        'result_type' : reporter_type,
                        'reporters' : ','.join(reporters)
                        })

    response = HttpResponse(template.render(context))
    
    
    log_entry.set_processing_time(log_start_time)
    log_entry.save()
    
    return response
Example #13
0
class Auth:
    name = ''
    chat_id = None
    authorize = False
    help = None
    tags = None
    alarms = None
    email = None

    def __init__(self, chat_id, bot ):
        conn = sqlite3.connect(dataBaseDjangoDir)
        cursor = conn.cursor()
        cursor.execute("""select * from usuarios_usuario""")
        conn.commit()
        query = (cursor.fetchall())
        for user in query:
            if user[4] == chat_id:
                self.name = user[1]
                self.email = user[4]
                self.authorize = True
                self.help = Help(chat_id)
                self.sensiTags = SensiTags(bot)
                self.graphic = Graphics()
                self.report = Reports()
        self.chat_id = chat_id



    def authUser(self):
        return self.authorize

    def unauthorized(self, bot):
        conn = sqlite3.connect(dataBaseDjangoDir)
        cursor = conn.cursor()
        cursor.execute("""select * from usuarios_usuario""")
        conn.commit()
        query = (cursor.fetchall())

        msg = 'Ei, meu nome Sensi!\n'
        msg = msg + 'Infelizmente vc não tem permissão para acessar meus dados.\n'
        msg = msg + '\nEntre em contato com uma das pessoas abaixo para se cadastrar no sistema:\n\n'
        for user in query:
            msg = msg + '*->* '
            msg = msg + '*' + user[1]+ '* - *' + str(user[3]) +'*\n'
        msg = msg + '\nAvise eles que seu chat id é: *' + str(self.chat_id) +'*'
        bot.send_message(self.chat_id, msg, parse_mode="markdown")

    def infoUsers(self, bot):
        msg = 'Ei, ' + self.name + '!\n'
        msg = msg + 'Aqui está a lista de usuários do meu sistema:\n\n'

        conn = sqlite3.connect(dataBaseDjangoDir)
        cursor = conn.cursor()
        cursor.execute("""select * from usuarios_usuario""")
        conn.commit()
        query = (cursor.fetchall())

        for user in query:
            msg = msg + '*->* nome: *' + user[1] + '*\n'
            msg = msg + '     e-mail: *' + user[2] + '*\n'
            msg = msg + '     telefone: *' + str(user[3]) + '*\n'
            msg = msg + '     chat id: *' + str(user[4]) + '*\n\n'
        msg = msg + 'Precisando de mais alguma coisa? É só me chamar :)'
        bot.send_message(self.chat_id, msg, parse_mode="markdown")

    def infoSystem(self, bot):
        msgSystem = self.name + self.help.infoSystem()
        bot.send_message(self.chat_id, msgSystem, parse_mode="markdown")

    def alarmsInfo(self, bot):
        msgAlarms = self.name + self.sensiTags.alarms.getInfo()
        bot.send_message(self.chat_id, msgAlarms, parse_mode="markdown")

    def infoTags(self, bot):
        msgTags = self.name + self.sensiTags.getInfo()
        bot.send_message(self.chat_id, msgTags , parse_mode="markdown" )

    def lastReg(self, bot):
        lastRegister = self.name + self.sensiTags.lastReg()
        bot.send_message(self.chat_id, lastRegister , parse_mode="markdown" )

    def reboot(self, bot):

        conn = sqlite3.connect(dataBaseDjangoDir)
        cursor = conn.cursor()
        cursor.execute("""select * from usuarios_usuario""")
        conn.commit()
        query = (cursor.fetchall())

        for user in query:
            if user[1] != self.name:
                msg ="*" + user[1] + "*, o usuário *"+self.name+"* pediu para o sistema ser reiniciado. Todos os usuários foram notificados.\n\nJá já estou de volta!"
                bot.send_message(user[4], msg , parse_mode="markdown" )
        msg = self.name + ", vc pediu para o sistema ser reiniciado. Todos os usuários foram notificados.\n\nJá já estou de volta!"
        bot.send_message(self.chat_id, msg, parse_mode="markdown")
        os.system("sudo reboot")

    def graphicsOneDay(self, bot):
        conn = sqlite3.connect(dataBaseDjangoDir)
        cursor = conn.cursor()
        cursor.execute("""SELECT * FROM tags_tag""")
        conn.commit()
        query = (cursor.fetchall())
        # trata se não existir SensiTags
        if len(query) > 0:
            msgGraphics ="Olá *" + self.name +"*"+ self.graphic.getInfo() + "do último dia. Lembrando que os gráficos devem demorar alguns segundos para chegar!"
            bot.send_message(self.chat_id, msgGraphics, parse_mode="markdown")
            self.graphic.makeAndSendGraphicAll(288, bot, self.chat_id)
        else:
            bot.send_message(self.chat_id, "Sensi aqui!\nParece que o seu sistema não possui SensiTags Cadastradas.", parse_mode="markdown")

    def graphics3Day(self, bot):

        conn = sqlite3.connect(dataBaseDjangoDir)
        cursor = conn.cursor()
        cursor.execute("""SELECT * FROM tags_tag""")
        conn.commit()
        query = (cursor.fetchall())
        #trata se não existir SensiTags
        if len(query)>0:
            msgGraphics ="Olá *" + self.name +"*"+ self.graphic.getInfo() + "dos últimos 3 dias. Lembrando que os gráficos devem demorar alguns minutinhos para chegar :)"
            bot.send_message(self.chat_id, msgGraphics, parse_mode="markdown")
            self.graphic.makeAndSendGraphicAll(700, bot, self.chat_id)
        else:
            bot.send_message(self.chat_id, "Sensi aqui!\nParece que o seu sistema não possui SensiTags Cadastradas.", parse_mode="markdown")

    def graphicsOneWeek(self, bot):
        conn = sqlite3.connect(dataBaseDjangoDir)
        cursor = conn.cursor()
        cursor.execute("""SELECT * FROM tags_tag""")
        conn.commit()
        query = (cursor.fetchall())
        #trata se não existir SensiTags
        if len(query)>0:
            msgGraphics ="Olá *" + self.name +"*"+ self.graphic.getInfo() + "dos últimos 7 dias. Lembrando que os gráficos devem demorar alguns minutinhos para chegar :)"
            bot.send_message(self.chat_id, msgGraphics, parse_mode="markdown")
            self.graphic.makeAndSendGraphicAll(2016, bot, self.chat_id)
        else:
            bot.send_message(self.chat_id, "Sensi aqui!\nParece que o seu sistema não possui SensiTags Cadastradas.", parse_mode="markdown")


    def getHelp(self, bot):
        bot.send_message(self.chat_id, self.help.helpMessage(), parse_mode="markdown")

    def reportOneDayAll(self, bot):
        conn = sqlite3.connect(dataBaseDjangoDir)
        cursor = conn.cursor()
        cursor.execute("""SELECT * FROM tags_tag""")
        conn.commit()
        query = (cursor.fetchall())
        # trata se não existir SensiTags
        if len(query) > 0:
            msgGraphics = "Ei, *" + self.name + "*!\nEstou te enviando o relatório completo de suas SensiTags dos últimos 1 dias. Lembrando que os isso pode demorar alguns minutinhos para chegar :)"
            bot.send_message(self.chat_id, msgGraphics, parse_mode="markdown")
            self.report.sendReportOneDayAll(bot, self.chat_id)
        else:
            bot.send_message(self.chat_id, "Sensi aqui!\nParece que o seu sistema não possui SensiTags Cadastradas.", parse_mode="markdown")

    def report3DaysAll(self, bot):
        conn = sqlite3.connect(dataBaseDjangoDir)
        cursor = conn.cursor()
        cursor.execute("""SELECT * FROM tags_tag""")
        conn.commit()
        query = (cursor.fetchall())
        # trata se não existir SensiTags
        if len(query) > 0:
            msgGraphics = "Ei, *" + self.name + "*!\nEstou te enviando o relatório completo de suas SensiTags dos últimos 3 dias. Lembrando que os isso pode demorar alguns minutinhos para chegar :)"
            bot.send_message(self.chat_id, msgGraphics, parse_mode="markdown")
            self.report.sendReport3DaysAll(bot, self.chat_id)
        else:
            bot.send_message(self.chat_id, "Sensi aqui!\nParece que o seu sistema não possui SensiTags Cadastradas.", parse_mode="markdown")

    def report7DaysAll(self, bot):
        conn = sqlite3.connect(dataBaseDjangoDir)
        cursor = conn.cursor()
        cursor.execute("""SELECT * FROM tags_tag""")
        conn.commit()
        query = (cursor.fetchall())
        # trata se não existir SensiTags
        if len(query) > 0:
            msgGraphics = "Ei, *" + self.name + "*!\nEstou te enviando o relatório completo de suas SensiTags dos últimos 7 dias. Lembrando que os isso pode demorar alguns minutinhos para chegar :)"
            bot.send_message(self.chat_id, msgGraphics, parse_mode="markdown")
            self.report.sendReport7DaysAll(bot, self.chat_id)
        else:
            bot.send_message(self.chat_id, "Sensi aqui!\nParece que o seu sistema não possui SensiTags Cadastradas.", parse_mode="markdown")
Example #14
0
import schedule
from settings import config
from reports import Reports

# O
o_reports = Reports(config['o']['source'], config['o']['destination'], config['archive'])
# Z
z_reports = Reports(config['z']['source'], config['z']['destination'], config['archive'])
# R
r_reports = Reports(config['r']['source'], config['r']['destination'], config['archive'])

# Schedule
schedule.every(10).minutes.do(o_reports.move_all)
# --------------------------------------------------------
schedule.every().day.at('03:00').do(o_reports.create_week_archive)
schedule.every().day.at('03:10').do(z_reports.create_week_archive)
schedule.every().day.at('03:20').do(r_reports.create_week_archive)
# --------------------------------------------------------
schedule.every().day.at('05:00').do(r_reports.move_period)
# --------------------------------------------------------
schedule.every().day.at('06:00').do(z_reports.move_or_copy)
schedule.every().day.at('08:00').do(z_reports.move_or_copy)
schedule.every().day.at('12:00').do(z_reports.move_or_copy)
schedule.every().day.at('14:00').do(z_reports.move_or_copy)
schedule.every().day.at('16:00').do(z_reports.move_or_copy)

if __name__ == '__main__':
    while True:
        schedule.run_pending()
Example #15
0
from flask import request, redirect, Flask, flash, render_template, send_from_directory, url_for, jsonify #pip install flask
from werkzeug.utils import secure_filename
import os,datetime,math
from customer import Customer 
from item import Item 
from payment import Payment
from transaction import Transaction
from goldprice import getTodaysGoldPrice
from reports import Reports
import util
# from util import encrypt
reports = Reports()
trans = Transaction()
payment = Payment()
item = Item()
app = Flask(__name__)
users = {'*****@*****.**': {'password': '******'}}
app.secret_key = 'super secret string'
customer = Customer()
UPLOAD_FOLDER = os.curdir+'\\uploads'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
app.config['SERVERNAME'] = "reddy:5000"

@app.route('/')
def home():
    return render_template("home.html",reports=get_reports())

@app.route('/uploads/<filename>')
def uploaded_file(filename):
Example #16
0
parser.add_argument('--settings', dest='settings', action='store', default='settings', help='settings file')
parser.add_argument('--reports', dest='reports', action='store', default=None, help='show reports')
parser.add_argument('--no-progress', dest='print_progress', action='store_false', default=True, help='show progress')
parser.add_argument('--print-keys', dest='print_keys', action='store_true', default=False, help='print keys')
parser.add_argument('--groups', dest='groups', action='store', default=None, help='filter keys to groups list separated by comma(,)')

args = parser.parse_args()


settings_file = args.settings or 'settings'
settings = __import__(settings_file, {}, {}, [])

p = Parser(settings, {'print_progress': args.print_progress, 'print_keys': args.print_keys})

if args.input_file:
    p.parse(args.input_file, int(args.limit_lines))

    if args.use_file:
        p.save_data(args.use_file)

    r = Reports(settings, {'groups': args.groups and args.groups.split(',')}, p.get_data())
else:
    r = Reports(settings, {'groups': args.groups and args.groups.split(',')}, args.use_file)

r.main(args.reports)


#import memcache
#mc = memcache.Client(['127.0.0.1:11211'], debug=0)
#print mc.get_stats()
Example #17
0
 def _get_html(self):
     for shop_id in self._get_shop_id():
         start_time = time.time()
         curls = self._get_curls(shop_id)
         if not curls:
             continue
         curl = random.choice(curls)
         page_num, used_page_nums, total_page = self._get_page_num(shop_id)
         session = requests.Session()
         while page_num:
             url, params, cookies, headers = self.format_request_params(
                 curl['curl'], page_num)
             while 1:
                 try:
                     proxy = Format._read("1", "proxy")
                     print(proxy)
                     if not proxy:
                         self._set_proxy()
                     proxies = {"https": "https://{}".format(proxy)}
                     r = session.get(url=url,
                                     params=params,
                                     cookies=cookies,
                                     headers=headers,
                                     proxies=proxies,
                                     stream=True)
                 except requests.exceptions.ProxyError:
                     self._set_proxy()
                     session = requests.Session()
                     continue
                 except requests.exceptions.InvalidURL:
                     self._set_proxy()
                     continue
                 except requests.exceptions.SSLError:
                     self._set_proxy()
                     continue
                 else:
                     break
             html = r.text.replace("\\", "")
             html = re.sub("jsonp\d+\(\"|\"\)", "", html)
             yield html, shop_id, curl, total_page, page_num
             spent_time = int(time.time() - start_time)
             used_page_nums.append(page_num)
             used_page_nums.sort()
             tspi = {  # tb_search_page_info
                 "used_page_nums":
                 ",".join([str(x) for x in used_page_nums]),
                 "spent_time": spent_time,
                 "last_date": datetime.date.today()
             }
             MySql.cls_update(db_setting=TEST_SERVER_DB_TEST,
                              t="tb_search_page_info",
                              set=tspi,
                              c={"shop_id": shop_id})
             page_num, used_page_nums, total_page = self._get_page_num(
                 shop_id)
         sql = "UPDATE tb_master SET flag='XiaJia',update_date='{}' WHERE shop_id='{}' AND update_date<'{}'".format(
             datetime.date.today(), shop_id, datetime.date.today())
         # print(sql)
         MySql.cls_update(db_setting=TEST_SERVER_DB_TEST, sql=sql)
     reports = Reports()
     reports.report([ids for ids in self._get_shop_id()])
Example #18
0
 def re(self, event=""):
     self.withdraw()
     Reports(self, self.main_root)
Example #19
0
class Engine(object):
    def __init__(self, dbPath, dbName):
        self.database = dbPath + dbName
        self.dataPath = dbPath
        self.visits = Visits()
        self.guests = Guests()
        self.reports = Reports(self)
        self.teams = Teams()
        self.accounts = Accounts()
        self.devices = Devices()
        self.unlocks = Unlocks()
        # needs path since it will open read only
        self.customReports = CustomReports(self.database)
        self.certifications = Certifications()
        self.members = Members()
        self.logEvents = LogEvents()

        if not os.path.exists(self.database):
            if not os.path.exists(dbPath):
                os.mkdir(dbPath)
            with self.dbConnect() as c:
                self.migrate(c, 0)
        else:
            with self.dbConnect() as c:
                data = c.execute('PRAGMA schema_version').fetchone()
                if data[0] != SCHEMA_VERSION:
                    self.migrate(c, data[0])

    def dbConnect(self):
        return sqlite3.connect(self.database,
                               detect_types=sqlite3.PARSE_DECLTYPES)

    def migrate(self, dbConnection, db_schema_version):
        if db_schema_version < SCHEMA_VERSION:
            self.visits.migrate(dbConnection, db_schema_version)
            self.members.migrate(dbConnection, db_schema_version)
            self.guests.migrate(dbConnection, db_schema_version)
            self.teams.migrate(dbConnection, db_schema_version)
            self.customReports.migrate(dbConnection, db_schema_version)
            self.certifications.migrate(dbConnection, db_schema_version)
            self.accounts.migrate(dbConnection, db_schema_version)
            self.devices.migrate(dbConnection, db_schema_version)
            self.unlocks.migrate(dbConnection, db_schema_version)
            self.logEvents.migrate(dbConnection, db_schema_version)
            dbConnection.execute('PRAGMA schema_version = ' +
                                 str(SCHEMA_VERSION))
        elif db_schema_version != SCHEMA_VERSION:  # pragma: no cover
            raise Exception("Unknown DB schema version" +
                            str(db_schema_version) + ": " + self.database)

    def injectData(self, dictValues):
        areas = {
            "visits": self.visits,
            "members": self.members,
            "guests": self.guests,
            "teams": self.teams,
            "customReports": self.customReports,
            "certifications": self.certifications,
            "accounts": self.accounts,
            "devices": self.devices,
            "unlocks": self.unlocks,
            "logEvents": self.logEvents
        }

        for (key, member) in areas.items():
            if key in dictValues:
                with self.dbConnect() as dbConnection:
                    member.injectData(dbConnection, dictValues[key])

    def getGuestLists(self, dbConnection):
        all_guests = self.guests.getList(dbConnection)

        building_guests = self.reports.guestsInBuilding(dbConnection)

        guests_not_here = [
            guest for guest in all_guests if guest not in building_guests
        ]

        return (building_guests, guests_not_here)
 def adjust_balance(cls, user_id: str, amount: Decimal) -> Decimal:
     "A method to adjust a user balance up or down"
     cls._wallets[user_id] = cls._wallets[user_id] + Decimal(amount)
     Reports.log_event(f"Balance adjustment for `{user_id}`. "
                       f"New balance = {cls._wallets[user_id]}")
     return cls._wallets[user_id]
 def get_balance(cls, user_id: str) -> Decimal:
     "A method to check a users balance"
     Reports.log_event(
         f"Balance check for `{user_id}` = {cls._wallets[user_id]}")
     return cls._wallets[user_id]
Example #22
0
def report(request):
    log_start_time = datetime.utcnow()
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/ui/login/?next=/ui/')

    sample_point_ids = []
    # create a log entry    
    log_entry = LogEntry()
    log_entry.user = request.user
    log_entry.timestamp = log_start_time
    log_entry.post_data = request.POST
    
    #check if the post was from an info window (single sample point)
    if request.POST.has_key('btnInfoWindow') \
        and request.POST.has_key('sample_point_id') \
        and request.POST.has_key('txtInfoStartDate') \
        and request.POST.has_key('txtInfoEndDate'):
         
        sample_point_ids.append(request.POST['sample_point_id'])
        start_date = request.POST.get('txtInfoStartDate')
        end_date = request.POST.get('txtInfoEndDate')
        report_type = 'FULL'
         
    elif request.POST.has_key('btnSidePanel')\
        and request.POST.has_key('sample_point') \
        and request.POST.has_key('txtSideStartDate') \
        and request.POST.has_key('txtSideEndDate') \
        and request.POST.has_key('radReportType'):
        
        report_type = request.POST.get('radReportType') 
        start_date = request.POST.get('txtSideStartDate') 
        end_date = request.POST.get('txtSideEndDate') 
        sample_point_ids = request.POST.getlist('sample_point')
    else:
        return HttpResponse('insufficient parameters')
    
    
    
    if report_type == 'SITE_COUNT':
        filename = Reports.get_filename(sample_point_ids, start_date, end_date, 'site-test-count')
        log_entry.event_type = 'rep_site_test_count'
    elif report_type == 'REPORTER_COUNT':
        filename = Reports.get_filename(sample_point_ids, start_date, end_date, 'reporter-test-count')
        log_entry.event_type = 'rep_test_count'
    else:
        filename = Reports.get_filename(sample_point_ids, start_date, end_date)
        log_entry.event_type = 'rep_full'
    
    # Create the HttpResponse object with the appropriate XLS header info.
    response = HttpResponse(mimetype="application/ms-excel")
    response['Content-Disposition'] = 'attachment; filename=%s' % filename
    
    if report_type == 'SITE_COUNT':
        wb = Reports.render_excel(Reports.get_test_counts(sample_point_ids, start_date, end_date))
    elif report_type == 'REPORTER_COUNT':
        wb = Reports.render_excel(Reports.get_reporter_test_counts(sample_point_ids, start_date, end_date))
    else:
        wb = Reports.get_basic(sample_point_ids, start_date, end_date)
        
    wb.save(response)
    
    log_entry.set_processing_time(log_start_time)
    log_entry.save()
    
    return response
Example #23
0
 def get_history() -> dict:
     "get the game history"
     return Reports.get_history()
from reports import Reports
import torch

# testing constants
MAX_EPISODE = 5000  # stop the training early and test the results

# don't move this- it creates circular dependencies.
report = Reports()

# flags
set_seed = True

# Program run constants
SEED = 0
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print('Device: {}'.format(DEVICE))
num_frames = 300000
VIDEO_INTERVAL = 100  # change to 1 to record all videos
NUM_FRAMES_STACKED = 4
XYZ_GOAL = [.2, .1, 1.2]  # More specific goal numbers [0.231, 0.105, 1.261]
SOLVED_DISTANCE = 1.0  #
WRITE_TO_FILE = True
REPORT_INTERVAL = 1  # write all the reports
SIZE = (512, 512)
LR = 1e-2  # Other LR values, was 1e-3 or 3e-4

# prioritized replay params
PRIORITY = False  # True runs with priority replay
ALPHA = .6  # alpha param for priority replay buffer
BETA = .4  # initial value of beta
BETA_ITERS = None  # number of iterations over which beta will be annealed from initial value