示例#1
0
    def migration(self):
        # MongoDB handler
        mdb_handler = MongoDB()
        if hasattr(c, "message"): return render("/error.html")

        for document in mdb_handler.collection.find(fields=["_id", "har"]):
            id = document["_id"]

            har = HAR(document["har"], True)

            har.analyze()

            domains_req_ratio = dict()
            domains_weight_ratio = dict()

            for key, value in har.domains.items():
                domains_req_ratio[key] = value[0]
                domains_weight_ratio[key] = value[1]

            data = {"full_load_time":       har.full_load_time,
                    "onload_event":         har.onload_event,
                    "start_render_time":    har.start_render_time,
                    "time_to_first_byte":   har.time_to_first_byte,
                    "total_dns_time":       har.total_dns_time,
                    "total_transfer_time":  har.total_transfer_time,
                    "total_server_time":    har.total_server_time,
                    "avg_connecting_time":  har.avg_connecting_time,
                    "avg_blocking_time":    har.avg_blocking_time,
                    "total_size":           har.total_size,
                    "text_size":            har.text_size,
                    "media_size":           har.media_size,
                    "cache_size":           har.cache_size,
                    "requests":             har.requests,
                    "redirects":            har.redirects,
                    "bad_requests":         har.bad_requests,
                    "domains":              len(har.domains),
                    "weights_ratio":        har.weight_ratio(),
                    "requests_ratio":       har.req_ratio(),
                    "domains_ratio":        har.domains}

            mdb_handler.collection.update({"_id": id}, {"$set": data})

        migration_handler = MongoDB(collection = "migration")
        migration_handler.collection.insert({"status": "ok"})

        redirect("/")
示例#2
0
    def upload(self):
        """Controller for uploads of new test results"""
        log.debug('-------------> attempting to Upload a file');

        # HAR initialization
        try:
            har = HAR(request.POST["file"].value)
        except:
            har = HAR(request.POST["file"])
        
        # Analysis of uploaded data
        if har.parsing_status == "Successful":
            # Parsing imported HAR file
            try:
                har.analyze()
            except Exception as error:
                return False, ": ".join([type(error).__name__, error.message])
            
            # Evaluate Page Speed scores
            if config["app_conf"]["ps_enabled"] == "true":
                scores = self._get_pagespeed_scores(har.har)
            else:
                scores = dict([("Total Score", 0)])
            
            # Add document to collection
            timestamp = time.strftime("%A, %B %d %Y %I:%M%p", time.localtime())

            result = {  "label":                har.label,
                        "url":                  har.url,
                        "timestamp":            timestamp,
                        "full_load_time":       har.full_load_time,
                        "onload_event":         har.onload_event,
                        "start_render_time":    har.start_render_time,
                        "time_to_first_byte":   har.time_to_first_byte,
                        "total_dns_time":       har.total_dns_time,
                        "total_transfer_time":  har.total_transfer_time,
                        "total_server_time":    har.total_server_time,
                        "avg_connecting_time":  har.avg_connecting_time,
                        "avg_blocking_time":    har.avg_blocking_time,
                        "total_size":           har.total_size,
                        "text_size":            har.text_size,
                        "media_size":           har.media_size,
                        "cache_size":           har.cache_size,
                        "requests":             har.requests,
                        "redirects":            har.redirects,
                        "bad_requests":         har.bad_requests,
                        "domains":              len(har.domains),
                        "ps_scores":            scores,
                        "har":                  har.origin,
                        "weights_ratio":        har.weight_ratio(),
                        "requests_ratio":       har.req_ratio(),
                        "domains_ratio":        har.domains}

            # MongoDB handler
            mdb_handler = MongoDB()
            if hasattr(c, "message"):
                return False, c.message
            else:
                mdb_handler.collection.insert(result)

            return True, har.label
        else:
            return False, har.parsing_status