def test_ms_to_time(): assert h.ms_to_time(None) is None assert h.ms_to_time(2203085216) == "25 days, 11:58:05"
def test_ms_to_time(): assert h.ms_to_time(None) is None assert h.ms_to_time(1000) == "0:00:01"
def job_summary_table(job) -> go.FigureWidget: job_url = f"{SH_URL}/{job.key}" job_state = api.get_job_state(job) job_close_reason = api.get_job_close_reason(job) no_of_scraped_items = api.get_items_count(job) no_of_errors = api.get_errors_count(job) job_runtime = api.get_runtime_s(job) / 1000 run_time = helpers.ms_to_time(job_runtime) crawling_speed = round(job_runtime / 60 / no_of_scraped_items, 3) request_success_ratio = round( api.get_requests_count(job) / float(no_of_scraped_items), 2) max_memusage = api.get_max_memusage(job) response_status_count = api.get_response_status_count(job) crawlera_stat_value = api.get_crawlera_user(job) if not crawlera_stat_value: crawlera_stat_value = "Not Used" job_stats_values = [ "Job URL", "Spider State", "Spider Close Reason", "Number of Scraped Items", "Number of Errors", "Runtime", "Request Success Ratio [requests/scraped items]", "Crawling Speed [items/min]", "Crawlera user", "Max Memory Usage [Bytes]", "Response Status Count", ] stats_values = [ '<a href="' + job_url + '">' + job_url + "</a>", job_state, job_close_reason, no_of_scraped_items, no_of_errors, run_time, request_success_ratio, crawling_speed, crawlera_stat_value, max_memusage, "200: " + str(response_status_count[0]) + "<br>" + "301: " + str(response_status_count[1]) + "<br>" + "404: " + str(response_status_count[2]) + "<br>" + "503: " + str(response_status_count[3]) + "<br>", ] trace = go.Table( columnorder=[1, 2], columnwidth=[300, 200], header=dict( values=["<b>Job Stat</b>", "<b>Stat Value</b>"], fill=dict(color="gray"), align=["left"] * 5, font=dict(color="black", size=14), height=30, ), cells=dict( values=[job_stats_values, stats_values], fill=dict(color="lightgrey"), font=dict(color="black", size=12), height=25, align=["left"] * 5, ), ) spider = job.metadata.get("spider") layout = go.Layout( title=f"Summary for spider {spider}", autosize=True, margin=dict(t=40, b=25, l=0, r=0), height=445, ) return go.FigureWidget(data=[trace], layout=layout)