Пример #1
0
def bidding_info_service(announce_id, url):
    participator = None
    if announce_id:
        participator = sc_crawler_query_all(company_bidding_info_by_id_query,
                                            (announce_id, ))
    elif url:
        participator = sc_crawler_query_all(company_bidding_info_by_url_query,
                                            (url, ))
    if participator:
        participator_object = collect_participator(participator)
        result = {
            "announceID": participator[0]["announceID"],
            "title": participator[0]["title"],
            "url": participator[0]["url"],
            "sourceKey":
            get_content_source_key(participator[0]["contentSource"]),
            "website": participator[0]["website"],
            "publishedDateTime": participator[0]["publishedDateTime"],
            "winningDate": participator[0]["winningDate"],
            "announceType": participator[0]["announceType"],
            "participatorObject": participator_object,
            "participator": participator_to_string(participator_object)
        }
        return result
    return None
Пример #2
0
def bidding_statistic_by_company_service(company_name, begin, end):
    parameters = {
        "company_name": company_name,
        "start_date": begin,
        "end_date": end
    }
    distribute = sc_crawler_query_all(
        bidding_result_statistic_by_company_query, parameters)
    statistic = {
        "bidCount": 0,
        "bidMoneyAmount": 0,
        "winCount": 0,
        "winMoneyAmount": 0
    }
    for item in distribute:
        for key in statistic.keys():
            statistic[key] += item[key] if item[key] else 0

    distribute.append(statistic)
    distribute = _format_statistic_by_company_result_data(distribute)
    distribute, statistic = distribute[:-1], distribute[-1]

    # 如果 statistic 中总投标次数为0时,返回None
    if statistic.get("bidCount") == 0:
        result = None
    else:
        result = {"provinceDistribution": distribute, "statistic": statistic}

    return result
Пример #3
0
def bidding_statistic_by_company_trend_service(company_name, base):
    parameters = {"company_name": company_name}
    trend_data = sc_crawler_query_all(
        bidding_result_statistic_by_company_trend_query, parameters)

    trend = {}
    for item in trend_data:
        year_month = item.pop("yearMonth")
        month = int(year_month[-2:])
        month = int((month - 1) / base) * base + 1
        year_month = year_month[:-2] + "%02d" % month
        if year_month not in trend:
            trend[year_month] = []
        trend[year_month].append(item)

    result = {}
    for year_month, distribute in trend.items():
        statistic = {
            "bidCount": 0,
            "bidMoneyAmount": 0,
            "winCount": 0,
            "winMoneyAmount": 0
        }

        distribute_collect = {}
        for item in distribute:
            province = item.get("province")
            if province not in distribute_collect:
                distribute_collect[province] = item
                for key in statistic.keys():
                    distribute_collect[province][
                        key] = item[key] if item[key] else 0
            else:
                for key in statistic.keys():
                    distribute_collect[province][
                        key] += item[key] if item[key] else 0
        distribute = distribute_collect.values()

        for item in distribute:
            for key in statistic.keys():
                statistic[key] += item[key] if item[key] else 0

        distribute.append(statistic)
        distribute = _format_statistic_by_company_result_data(distribute)
        distribute, statistic = distribute[:-1], distribute[-1]

        result[year_month] = {
            "provinceDistribution": distribute,
            "statistic": statistic
        }

    return result
Пример #4
0
def bidding_company_info_service(company_name, st_datetime, ed_datetime):
    items = sc_crawler_query_all(company_bidding_info_query,
                                 (company_name, st_datetime, ed_datetime))
    coding_filter(items)

    announce_id, participator, result, results = None, [], {}, []
    for item in items:
        if announce_id != item["announceID"]:
            announce_id = item["announceID"]
            if participator and result:
                result["participatorObject"] = collect_participator(
                    participator)
                result["participator"] = participator_to_string(
                    result["participatorObject"])
                results.append(result)
                participator, result = [], {}

        if not result:
            result["announceID"] = item["announceID"]
            result["title"] = item["title"]
            result["url"] = item["url"]
            result["sourceKey"] = get_content_source_key(item["contentSource"])
            result["website"] = item["website"]
            result["publishedDateTime"] = item["publishedDateTime"]
            result["winningDate"] = item["winningDate"]
            result["announceType"] = item["announceType"]

        part = {
            "resultID": item["resultID"],
            "winningCompany": item["winningCompany"],
            "winningAmount": item["winningAmount"],
            "unit": item["unit"],
            "currency": item["currency"],
            "roleName": item["roleName"],
            "candidateRank": item["candidateRank"],
            "segmentName": item["segmentName"]
        }
        participator.append(part)

    if participator and result:
        result["participatorObject"] = collect_participator(participator)
        result["participator"] = participator_to_string(
            result["participatorObject"])
        # result["participator"] = participator_to_string(participator)
        results.append(result)

    return results
Пример #5
0
def bidding_statistic_service(op,
                              begin,
                              end,
                              project_type=None,
                              province=None,
                              city=None,
                              county=None,
                              top=10,
                              page=0,
                              page_size=10):
    parameters = {
        "start_date": begin,
        "end_date": end,
        "project_type": project_type,
        "skip_n": page * page_size,
        "province": province,
        "city": city,
        "county": county,
        "page_size": page_size,
        "top_n": top
    }

    sc_crawler_non_query(set_work_mem_32m_non_query)

    if op == "amountCountRegion":
        if not province:
            query = get_statistic_query(
                nation_amount_count_base_on_province_query,
                project_type,
                province,
                city=None,
                county=None)
            result = sc_crawler_query_all(query, parameters)
        elif province in (u"北京市", u"上海市", u"天津市", u"重庆市"):
            query = get_statistic_query(
                province_amount_count_base_on_county_query,
                project_type,
                province,
                city=None,
                county=None)
            result = sc_crawler_query_all(query, parameters)
            region, default_region_name = u"county", u"市级"
            t = [i for i in range(len(result)) if result[i][region] is None]
            for i in t:
                result[i][region] = default_region_name
            for i, it in enumerate(result):
                result[i]["city"] = it["county"]
                del result[i]["county"]
        else:
            query = get_statistic_query(
                province_amount_count_base_on_city_query,
                project_type,
                province,
                city=None,
                county=None)
            result = sc_crawler_query_all(query, parameters)
            region, default_region_name = u"city", u"省级"
            t = [i for i in range(len(result)) if result[i][region] is None]
            for i in t:
                result[i][region] = default_region_name

        for i, it in enumerate(result):
            for reg in ["province", "city", "county"]:
                if reg in it:
                    result[i]["shortName"] = get_keyword(it[reg])
                    break

        return transform_amount(result)

    elif op == "amountCountDate":
        query = get_statistic_query(amount_count_base_on_date_query,
                                    project_type, province, city, county)
        result = sc_crawler_query_all(query, parameters)
        return transform_amount(result)

    elif op == "topRole":
        query = get_statistic_query(top_n_amount_base_on_purchaser_query,
                                    project_type, province, city, county)
        top_pur = transform_amount(sc_crawler_query_all(query, parameters))
        query = get_statistic_query(top_n_amount_base_on_agent_query,
                                    project_type, province, city, county)
        top_agt = transform_amount(sc_crawler_query_all(query, parameters))
        query = get_statistic_query(top_n_amount_base_on_winner_query,
                                    project_type, province, city, county)
        top_win = transform_amount(sc_crawler_query_all(query, parameters))
        if len(top_pur) > 0 or len(top_agt) or len(top_win) > 0:
            result = {
                "topPurchasers": top_pur,
                "topAgents": top_agt,
                "topWinners": top_win
            }
        else:
            result = None
        return result

    elif op == "winnerInfo":
        query = get_statistic_query(winner_info_query, project_type, province,
                                    city, county)
        result = sc_crawler_query_all(query, parameters)
        for i, item in enumerate(result):
            if province in (u"北京市", u"上海市", u"天津市", u"重庆市"):
                result[i]["city"] = item["county"]
            del result[i]["county"]
        return transform_amount(result)

    elif op == "winnerInfoCount":
        query = get_statistic_query(winner_info_count_query, project_type,
                                    province, city, county)
        result = sc_crawler_query_one(query, parameters)
        return result

    else:
        return []