如何计算组合经验

2024-09-28 01:32:20 发布

您现在位置:Python中文网/ 问答频道 /正文

函数中包含以下内容:

    edu = sorted(context.education, key=lambda studied: studied["studied_to"], reverse=True)
    #print edu[0].studied_to

    job_history = []
    for job in context.job_history:
        if edu[0].fields_of_study in job.industries:
            from_ = job.from_
            to_ = job.to_
            industries = job.industries
            rd = rdelta.relativedelta(to_, from_) # get date difference 
            # I suspect that combined exp calculation would be done here.
            experience = "{0.years} Years {0.months} Months".format(rd) #get Year - Month format
            #print experience
            job_history.append({"job_title": job_title,
                           "company_name": company_name,
                           "from_": from_,
                           "to_": to_,
                           "industries": industries,
                           "experience": experience})

    j = sorted(job_history, key=lambda s: s["to_"])
    #print j[0]["job_title"]
    return {"relocate_list": provinces,
            "disabilities_dict": disabilities,
            "industries_list": industry_dict,
            "job_history_sorted": j,
            "education_sorted": edu}

我可以从上面的代码每一个工作的经验。有没有办法计算出综合经验。
目前,假设用户在IT行业有/有多个工作,为了论证,上面的代码将给我例如1 Years 0 Months1 Years 4 Months。你知道吗

如何计算组合经验,使上面的例子是2 Years 4 Months?你知道吗

我试过:

rd += rd

但这加上了相同的日期,即

 1 Years 4 Months + 1 Years 4 Months

将输出:

2 Years 8 Months

Tags: tofromtitlejob经验rdhistoryexperience
1条回答
网友
1楼 · 发布于 2024-09-28 01:32:20

为什么不创建一个新变量来保存相对增量并在循环外显示它,比如:

job_history = []
total_exp = rdelta.relativedelta()
for job in context.job_history:
    if edu[0].fields_of_study in job.industries:
        from_ = job.from_
        to_ = job.to_
        industries = job.industries
        rd = rdelta.relativedelta(to_, from_) # get date difference 
        total_exp += rd
        job_history.append({"job_title": job_title,
                       "company_name": company_name,
                       "from_": from_,
                       "to_": to_,
                       "industries": industries,
                       "experience": experience})
 # I suspect that combined exp calculation would be done here.
 experience = "{0.years} Years {0.months} Months".format(total_exp) #get Year - Month format
 #print experience

相关问题 更多 >

    热门问题