def get(**kwargs):
        """ Method to provide detailed Information of Duplication-List Table """

        try:
            total_count = 0
            oem_res = {"total_count": total_count, "oem_response": []}

            logins = db.session.query(OemLogins).all()
            login_dict = dict(
                (login.oem_id, login.oem_name) for login in logins).items()

            if kwargs['filter'] == "pending_imeis":

                total_count = OemResponse.query.filter(
                    OemResponse.oem_serial_no == None).count()
                oem_res["total_count"] = total_count

                pending_imeis = OemResponse.query.filter(OemResponse.oem_serial_no == None).order_by(OemResponse.id)\
                                                 .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = oem_row_formatter(pending_imeis, login_dict)

            elif kwargs['filter'] == "responded_imeis":

                total_count = OemResponse.query.filter(
                    OemResponse.oem_serial_no != None).count()
                oem_res["total_count"] = total_count

                responded_imeis = OemResponse.query.filter(OemResponse.oem_serial_no != None).order_by(OemResponse.id)\
                                                   .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = oem_row_formatter(responded_imeis, login_dict)

            else:
                return custom_json_response(
                    _("selected Filter is not applicable"),
                    STATUS_CODES.get('BAD_REQUEST'), MIME_TYPES.get('JSON'))

            oem_res["oem_response"] = oem_res["oem_response"] + search

            return Response(json.dumps(oem_res),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(_("Error occurred while retrieving OEM response."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
Beispiel #2
0
    def get():
        """ Method to provide statistics of OEM Logins and related GSMA Brands """

        try:

            var1 = "oem_logins_detail"
            var2 = "gsma_brands_detail"
            oem_summary = {var1: {}, var2: {}}

            oem_summary[var2]["unique_brands"], oem_summary[var1]["approved_oems"], \
            oem_summary[var1]["pending_oems"], oem_summary[var2]["total_tacs"], \
            oem_summary[var1]["total_oems"], oem_summary[var1]["deleted_oems"], \
            oem_summary[var2]["associated_brands"], oem_summary[var2]["unassociated_brands"] \
            = dashboard_counts("summary")

            return Response(json.dumps(oem_summary),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info("Error occurred while retrieving OEM details.")
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get():
        """ Method to provide statistics of uploaded duplication lists """

        try:
            tmp = "duplication_list_Stats"
            duplist_stat = {tmp: {}}

            duplist_stat[tmp]["total_imeis"] = DupList.query.filter().count()

            duplist_stat[tmp]["processed_imeis"] = DupList.query.filter(
                DupList.imei_status != None).count()

            duplist_stat[tmp]["pending_imeis"] = duplist_stat[tmp][
                "total_imeis"] - duplist_stat[tmp]["processed_imeis"]

            duplist_stat[tmp]["genuine_imeis"] = DupList.query.filter(
                DupList.imei_status == True).count()

            duplist_stat[tmp]["duplicated_imeis"] = DupList.query.filter(
                DupList.imei_status == False).count()

            duplist_stat[tmp]["sms_notified_imeis"] = DupList.query.filter(
                DupList.sms_notification == True).count()

            duplist_stat[tmp]["sms_awaited_imeis"] = DupList.query.filter(
                DupList.sms_notification == None).count()

            start_date = (datetime.today() -
                          timedelta(days=conf['threshold_days'])).date()
            duplist_stat[tmp]["threshold_crossed_imeis"] = DupList.query.filter(DupList.list_upload_date < start_date)\
                                                                        .count()

            return Response(json.dumps(duplist_stat),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(
                _("Error occurred while retrieving Duplication List detail."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
Beispiel #4
0
    def get():
        """ Method to provide summary of users' response """

        try:
            t = "user_summary"
            user_dict = {t: {}}
            user_dict[t]["pending_imeis"] = UserResponse.query.filter(
                UserResponse.user_serial_no == None).count()
            user_dict[t]["responded_imeis"] = UserResponse.query.filter(
                UserResponse.user_serial_no != None).count()

            return Response(json.dumps(user_dict),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info("Error occurred while retrieving OEM details.")
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get():
        """method to get Dashboard Counts"""

        try:
            brand_count, approved_logins, pending_logins, total_tacs = dashboard_counts(
                "counters")

            return Response(json.dumps({
                "unique_brands": brand_count,
                "total_tacs": total_tacs,
                "approved_logins": approved_logins,
                "pending_logins": pending_logins
            }),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(
                "Error occurred while retrieving dashboard counts.")
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
Beispiel #6
0
    def get():
        """ Method to provide summary of users' response """

        try:

            oem_res = {"oem_response": []}
            login_dict = {}

            logins = db.session.query(OemResponse.oem_id).group_by(
                OemResponse.oem_id).all()

            for login in logins:
                qry = OemLogins.query.filter(
                    OemLogins.oem_id == login[0]).first()

                if qry:
                    login_dict["oem"] = qry.oem_name
                else:
                    login_dict["oem"] = "unknown"

                login_dict["pending_imeis"], login_dict[
                    "responded_imeis"] = oem_counts(login[0])

                oem_res["oem_response"].append(dict(login_dict))

            return Response(json.dumps(oem_res),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(_("Error occurred while retrieving OEM response."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get(**kwargs):
        """ Method to provide detailed Information of Duplication-List Table """

        try:

            if kwargs['filter'] == "pending_imeis":

                total_count = UserResponse.query.filter(
                    UserResponse.user_serial_no == None).count()

                qry = UserResponse.query.filter(UserResponse.user_serial_no == None).order_by(UserResponse.id)\
                                        .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = user_row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "responded_imeis":

                total_count = UserResponse.query.filter(
                    UserResponse.user_serial_no != None).count()

                qry = UserResponse.query.filter(UserResponse.user_serial_no != None).order_by(UserResponse.id)\
                                        .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = user_row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "genuine_imeis":

                total_count = UserResponse.query.filter(
                    UserResponse.uid_status == True).count()

                qry = UserResponse.query.filter(UserResponse.uid_status == True).order_by(UserResponse.id)\
                                        .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = user_row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "duplicated_imeis":

                total_count = UserResponse.query.filter(
                    UserResponse.uid_status == False).count()

                qry = UserResponse.query.filter(UserResponse.uid_status == False).order_by(UserResponse.id)\
                                        .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = user_row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            else:
                return custom_json_response(
                    _("selected Filter is not applicable"),
                    STATUS_CODES.get('BAD_REQUEST'), MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(
                _("Error occurred while retrieving User response."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
Beispiel #8
0
    def get(**kwargs):
        """ Method to provide detailed Information of Duplication-List Table """

        try:

            if kwargs['filter'] == "all_imeis":

                total_count = db.session.query(DupList).count()

                qry = [
                    d for d in db.session.query(DupList).order_by(DupList.id).
                    offset(kwargs['start']).limit(kwargs['limit']).all()
                ]

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "processed_imeis":

                total_count = DupList.query.filter(
                    DupList.imei_status != None).count()

                qry = DupList.query.filter(DupList.imei_status != None).order_by(DupList.id).offset(kwargs['start'])\
                                   .limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "pending_imeis":

                total_count = DupList.query.filter(
                    DupList.imei_status == None).count()

                qry = DupList.query.filter(DupList.imei_status == None).order_by(DupList.id).offset(kwargs['start']) \
                                   .limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "genuine_imeis":

                total_count = DupList.query.filter(
                    DupList.imei_status == True).count()

                qry = DupList.query.filter(DupList.imei_status == True).order_by(DupList.id).offset(kwargs['start']) \
                                   .limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "duplicated_imeis":

                total_count = DupList.query.filter(
                    DupList.imei_status == False).count()

                qry = DupList.query.filter(DupList.imei_status == False).order_by(DupList.id).offset(kwargs['start']) \
                                   .limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "sms_notified_imeis":

                total_count = DupList.query.filter(
                    DupList.sms_notification == True).count()

                qry = DupList.query.filter(DupList.sms_notification == True).order_by(DupList.id)\
                                   .offset(kwargs['start']).limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "sms_pending_imeis":

                total_count = DupList.query.filter(
                    DupList.sms_notification == None).count()

                qry = DupList.query.filter(DupList.sms_notification == None).order_by(DupList.id)\
                                   .offset(kwargs['start']).limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "threshold_crossed_imeis":

                start_date = (datetime.today() -
                              timedelta(days=conf['threshold_days'])).date()

                total_count = DupList.query.filter(
                    DupList.list_upload_date < start_date).count()

                qry = DupList.query.filter(DupList.list_upload_date < start_date).order_by(DupList.id)\
                                   .offset(kwargs['start']).limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            else:
                return custom_json_response(
                    _("selected Filter is not applicable"),
                    STATUS_CODES.get('BAD_REQUEST'), MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(
                _("Error occurred while retrieving Duplication-List Details."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()