def save():
    '''Create Govern procurements folder & save the procurements details for agency into txt file in Govern Procurement folder'''
    try:
        Create_Folder()
        agency_to_procurements = data_holder.create_dict_for_list(
            data_holder.procurements,
            'agency')  #Create dictionary to store procurement information

        for agency in agency_to_procurements:
            folder = './Govern Procurement/'
            file_path = folder + '%s.txt' % agency  #Convert government-procurement-via-gebiz csv file to txt file, and save the txt file to Govern Procurement folder
            with open(file_path,
                      'w') as f:  #Open the txt file as writable file
                for procurement in agency_to_procurements[agency]:
                    f.write(procurement.display_text() +
                            '\n')  #Display the procurement details in text

                    f.write('=' * 1000 + '\n')  #Divider

        tkMessageBox.showinfo(
            "Message", "File save to Govern Procurement folder successful"
        )  #Message dialog box pop out when file save successful

    except:
        tkMessageBox.showerror(
            "Error", "Unable to save file"
        )  #Error message dialog box pop out when file was not save successful
示例#2
0
def init_data():
    if is_initialized():
        return

    global amt_awarded_to_reg
    global amt_awarded_to_unreg
    global top5_contractors_and_amount

    contractor_dict = data_holder.create_dict_for_list(data_holder.contractors,
                                                       'company_name')
    company_awarded_amt_dict = {}

    for procurement in data_holder.procurements:
        if not procurement.awarded:
            continue

        if procurement.supplier_name in contractor_dict:
            company_awarded_amt_dict.setdefault(procurement.supplier_name, 0)
            company_awarded_amt_dict[
                procurement.supplier_name] += procurement.awarded_amt
            amt_awarded_to_reg += procurement.awarded_amt
        else:
            amt_awarded_to_unreg += procurement.awarded_amt

    sorted_company_names = sorted(
        company_awarded_amt_dict.keys(),
        key=company_awarded_amt_dict.get,
        reverse=True
    )  # sort keys in descending order based on value of a given key
    # create a list of tuples containing (company_name, total procurement amount)
    top5_contractors_and_amount = map(
        lambda c: (c, company_awarded_amt_dict[c]), sorted_company_names[:5])
def generate_stats():
    """
    make a dict in the following format
    {
        company_name: contractor
    }
    """
    contractor_dict = data_holder.create_dict_for_list(data_holder.contractors,
                                                       'company_name')
    procurement_list = data_holder.procurements
    procurement_count_dict = {}
    registered_contractors_names = set()
    unregistered_contractors_count = 0
    for procurement in procurement_list:
        if not procurement.awarded:  # skip if it is not awarded to anyone
            continue
        if (procurement.supplier_name
                in contractor_dict):  # a registered contractor
            registered_contractors_names.add(procurement.supplier_name)
        else:  # a unregistered contractor
            unregistered_contractors_count += 0

        if (not procurement.supplier_name in procurement_count_dict
            ):  # when the dictionary do not have the company name as key
            procurement_count_dict[
                procurement.
                supplier_name] = 0  # we initialize it to zero so we can add on to it later
        procurement_count_dict[procurement.supplier_name] += 1

    sorted_company_names = sorted(procurement_count_dict.keys(), \
                                     key=procurement_count_dict.get, \
                                     reverse=True) # sort keys in descending order based on value of a given key
    top_5_company_names = sorted_company_names[:5]

    result = []
    result.append('Registered contractors:')

    result.extend(registered_contractors_names)
    result.append('====')
    result.append('Top 5 companies with the most tenders:')

    top_5_company_name_and_tenders = map(lambda name: \
            '%s with %d tenders' % (name, procurement_count_dict[name]), top_5_company_names)
    result.extend(top_5_company_name_and_tenders)

    result.append('====')
    result.append('Number of unregistered contractors: %d' \
                  % unregistered_contractors_count)
    result.append('====')
    result.append('Number of registered contractors: %d' \
                  % len(registered_contractors_names))

    return '\n'.join(result)
 def group_topic_procurements(self, tender_nos_by_topics):
     """
     Convert tender numbers grouped by their topics to procurements grouped by topic
     then assigned the variable grouped_topic_procurements
     :param tender_nos_by_topics:
     :return: None
     """
     tender_no_to_procurements = data_holder.create_dict_for_list(
         data_holder.procurements, 'tender_no')
     self.grouped_topic_procurements = []
     for i in range(len(tender_nos_by_topics)):
         topics = tender_nos_by_topics[i]
         # convert the list of tender numbers to procurements object
         procurements = map(lambda t: tender_no_to_procurements[t][0],
                            topics)
         self.grouped_topic_procurements.append(procurements)
示例#5
0
def get_registered_contractors():
    # at this point the cache is not yet set
    # so we initialize it
    registered_contractors = set()
    contractor_dict = data_holder.create_dict_for_list(data_holder.contractors,
                                                       'company_name')
    for procurement in data_holder.procurements:
        if not procurement.awarded:
            continue

        if procurement.supplier_name not in contractor_dict:
            continue

        for contractor in contractor_dict[procurement.supplier_name]:
            registered_contractors.add(contractor)

    return registered_contractors
示例#6
0
    def __init__(self, parent):
        tk.Toplevel.__init__(self, parent)
        self.minsize(500, 400)
        self.title("Workheads")

        self.name_to_contractors = data_holder.create_dict_for_list(
            data_holder.contractors, 'company_name')

        self.listbox = tk.Listbox(self, width=30, selectmode=tk.SINGLE)
        self.listbox.bind("<Double-Button-1>", self.listbox_item_clicked)
        self.listbox.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
        self.set_workhead_categories_in_listbox()

        self.output_tb = OutputTextBox(self)
        self.output_tb.output_text.config(height=10)
        self.output_tb.grid(row=0, column=1, sticky=(tk.W, tk.E))
        self.grab_set()
def init_data():
    """
    Contains the function 5 logic that sets the variables containing the result for caching
    :return: None
    """
    if is_initialized():  # checks if the result variables are already set
        return

    # result variables are not set
    global _amt_awarded_to_reg
    global _amt_awarded_to_unreg
    global _top5_contractors_and_amount
    global _reg_contractors_and_amount
    global _unreg_contractors_and_amount

    contractor_dict = data_holder.create_dict_for_list(data_holder.contractors, 'company_name')
    company_awarded_amt_dict = {}
    reg_company_names = []
    unreg_company_names = []

    for procurement in data_holder.procurements:
        # skip not awarded procurement
        if not procurement.awarded:
            continue

        # group total procurements' awarded amount by company
        company_awarded_amt_dict.setdefault(procurement.supplier_name, 0)
        company_awarded_amt_dict[procurement.supplier_name] += procurement.awarded_amt

        # if supplier is registered
        if procurement.supplier_name in contractor_dict:
            _amt_awarded_to_reg += procurement.awarded_amt
            reg_company_names.append(procurement.supplier_name)
        else:
            _amt_awarded_to_unreg += procurement.awarded_amt
            unreg_company_names.append(procurement.supplier_name)

    # sorted the company names by total procurement amount
    sorted_company_names = sorted(company_awarded_amt_dict.keys(),
                                  key=company_awarded_amt_dict.get,
                                  reverse=True)
    # create a list of tuples containing (company_name, total procurement amount)
    _top5_contractors_and_amount = map(lambda c: (c, company_awarded_amt_dict[c]), sorted_company_names[:5])
    _reg_contractors_and_amount = map(lambda c: (c, company_awarded_amt_dict[c]), reg_company_names)
    _unreg_contractors_and_amount = map(lambda c: (c, company_awarded_amt_dict[c]), unreg_company_names)
示例#8
0
def get_registered_contractors_supplier():
    '''Get the list of contractors that is awarded to supplier'''
    # at this point the cache is not yet set
    # so we initialize it
    registered_contractors = set()
    contractor_dict = data_holder.create_dict_for_list(data_holder.contractors,
                                                       'company_name')
    #loop through the csv file and check which contractor is a registered vendor and is awarded to suppliers
    for procurement in data_holder.procurements:
        if not procurement.awarded:
            continue

        if procurement.supplier_name not in contractor_dict:
            continue

        for contractor in contractor_dict[procurement.supplier_name]:
            if procurement.tender_detail_status == "Awarded to Suppliers":
                registered_contractors.add(contractor)

    return registered_contractors
def agencyamt(category):
    '''search parametres go here'''

    technology = ['Technology', 'Media', 'Communications']
    transport = ['Transport']
    government = ['Prime Minister', 'Parliament']
    law = ['Attorney', 'Law', 'Judiciary']
    publicService = [
        'Social', 'Fund', 'Culture', 'Family', 'Energy', 'Intellectual',
        'Manpower', 'Arts', 'National', 'Parks', 'Utilities', 'Workforce',
        'Tote', 'Labor'
    ]
    finance = [
        'Accounting', 'Auditor', 'Commission', 'Project', 'Casino', 'Economic',
        'Finance', 'Enterprise', 'Revenue', 'Trade'
    ]
    clubs = [
        'Aviation', 'Istana', 'Corporation', 'Islam', 'Heritage', 'Library',
        'Productivity', 'Rehabilitative', 'Sports'
    ]
    health = ['Food', 'Health']
    housing = ['Estate', 'Housing', 'Redevelopment', 'Land']
    maritime = ['Maritime']
    education = [
        'Education', 'Polytechnic', 'College', 'Examinations', 'School',
        'Institute', 'University', 'Science', 'SkillsFuture'
    ]
    defence = ['Defence']
    '''storing lists go here'''

    technologyList = []
    transportList = []
    governmentList = []
    financeList = []
    clubsList = []
    maritimeList = []
    educationList = []
    lawList = []
    healthList = []
    housingList = []
    defenceList = []
    publicServiceList = []
    agency_to_procurements = data_holder.create_dict_for_list(
        data_holder.procurements, 'agency')

    agency_to_awarded_amt = {}
    # convert the list of procurement to awarded amount
    for agency in agency_to_procurements:
        agency_to_awarded_amt[agency] = sum(
            [p.awarded_amt for p in agency_to_procurements[agency]])

        if has_any_word_in_sentence(agency, law):
            lawList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, defence):
            defenceList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, publicService):
            publicServiceList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, technology):
            technologyList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, transport):
            transportList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, government):
            governmentList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, finance):
            financeList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, clubs):
            clubsList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, maritime):
            maritimeList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, education):
            educationList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, health):
            healthList.append(agency_to_awarded_amt[agency])
        elif has_any_word_in_sentence(agency, housing):
            housingList.append(agency_to_awarded_amt[agency])

    if category == 'Law':
        totalspend = sum(lawList)
        return totalspend
    elif category == 'Defence':
        totalspend = sum(defenceList)
        return totalspend
    elif category == 'Public Service':
        totalspend = sum(publicServiceList)
        return totalspend
    elif category == 'Technology':
        totalspend = sum(technologyList)
        return totalspend
    elif category == 'Transport':
        totalspend = sum(transportList)
        return totalspend
    elif category == 'Government':
        totalspend = sum(governmentList)
        return totalspend
    elif category == 'Finance':
        totalspend = sum(financeList)
        return totalspend
    elif category == 'Clubs':
        totalspend = sum(clubsList)
        return totalspend
    elif category == 'Maritime':
        totalspend = sum(maritimeList)
        return totalspend
    elif category == 'Education':
        totalspend = sum(educationList)
        return totalspend
    elif category == 'Health':
        totalspend = sum(healthList)
        return totalspend
    elif category == 'Housing':
        totalspend = sum(housingList)
        print totalspend
        return totalspend
def txtdetails():
    agency_to_procurements = data_holder.create_dict_for_list(
        data_holder.procurements, 'agency')
    for agency in agency_to_procurements:
        agencylist.append(agency)