Merge branch 'only_task'
This commit is contained in:
commit
e9754677c9
1
answer/1try.txt
Normal file
1
answer/1try.txt
Normal file
@ -0,0 +1 @@
|
||||
ID 2: Data Engineer в Тинькофф, Москва — от 180000 до 250000ID 6: Senior Python Developer в Wildberries, Москва — от 200000 до 300000
|
||||
@ -1,9 +1,9 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Python ðàçðàáîò÷èê",
|
||||
"company": "ßíäåêñ",
|
||||
"city": "Ìîñêâà",
|
||||
"title": "Python разработчик",
|
||||
"company": "Яндекс",
|
||||
"city": "Москва",
|
||||
"salary_from": 150000,
|
||||
"salary_to": 200000,
|
||||
"skills": ["Python", "SQL", "Django", "PostgreSQL"],
|
||||
@ -12,8 +12,8 @@
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Data Engineer",
|
||||
"company": "Òèíüêîôô",
|
||||
"city": "Ìîñêâà",
|
||||
"company": "Тинькофф",
|
||||
"city": "Москва",
|
||||
"salary_from": 180000,
|
||||
"salary_to": 250000,
|
||||
"skills": ["Python", "SQL", "Spark", "Airflow"],
|
||||
@ -23,7 +23,7 @@
|
||||
"id": 3,
|
||||
"title": "Backend Developer",
|
||||
"company": "Ozon",
|
||||
"city": "Ñàíêò-Ïåòåðáóðã",
|
||||
"city": "Санкт-Петербург",
|
||||
"salary_from": 130000,
|
||||
"salary_to": 170000,
|
||||
"skills": ["Python", "FastAPI", "MongoDB"],
|
||||
@ -32,8 +32,8 @@
|
||||
{
|
||||
"id": 4,
|
||||
"title": "Data Analyst",
|
||||
"company": "ßíäåêñ",
|
||||
"city": "Ìîñêâà",
|
||||
"company": "Яндекс",
|
||||
"city": "Москва",
|
||||
"salary_from": 140000,
|
||||
"salary_to": 180000,
|
||||
"skills": ["Python", "SQL", "Tableau"],
|
||||
@ -42,8 +42,8 @@
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Junior Python Developer",
|
||||
"company": "Ñáåð",
|
||||
"city": "Ìîñêâà",
|
||||
"company": "Сбер",
|
||||
"city": "Москва",
|
||||
"salary_from": 100000,
|
||||
"salary_to": 130000,
|
||||
"skills": ["Python", "SQL", "Git"],
|
||||
@ -53,7 +53,7 @@
|
||||
"id": 6,
|
||||
"title": "Senior Python Developer",
|
||||
"company": "Wildberries",
|
||||
"city": "Ìîñêâà",
|
||||
"city": "Москва",
|
||||
"salary_from": 200000,
|
||||
"salary_to": 300000,
|
||||
"skills": ["Python", "SQL", "Kafka", "Kubernetes"],
|
||||
@ -63,7 +63,7 @@
|
||||
"id": 7,
|
||||
"title": "Full Stack Developer",
|
||||
"company": "Avito",
|
||||
"city": "Ìîñêâà",
|
||||
"city": "Москва",
|
||||
"salary_from": 170000,
|
||||
"salary_to": 220000,
|
||||
"skills": ["Python", "JavaScript", "React", "SQL"],
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import json
|
||||
import os
|
||||
import csv
|
||||
from collections import Counter
|
||||
def load_vacancies(filepath: str) -> list[dict]:
|
||||
try:
|
||||
@ -9,20 +7,18 @@ def load_vacancies(filepath: str) -> list[dict]:
|
||||
except:
|
||||
print()
|
||||
return []
|
||||
|
||||
def filter_by_city(vacancies: list[dict], city: str) -> list[dict]:
|
||||
return [i for i in vacancies if i.get('city','').lower() == city.lower()]
|
||||
def filter_by_skills(vacancies: list[dict], required_skills: list[str]) -> list[dict]:
|
||||
return [i for i in vacancies if all(skill.lower() in set(k.lower() for k in i.get('skills')) for skill in required_skills ) ]
|
||||
def filter_by_salary(vacancies: list[dict], min_salary: int) -> list[dict]:
|
||||
return [v for v in vacancies if v.get('salary_to') and v.get('salary_from') and v.get('salary_to')>= min_salary and v.get('salary_form')> min_salary]
|
||||
return [v for v in vacancies if v.get('salary_to') and v.get('salary_from') and v.get('salary_to')>= min_salary and v.get('salary_from')> min_salary]
|
||||
def extract_unique_companies(vacancies: list[dict]) -> list[str]:
|
||||
return {v.get('company') for v in vacancies if v.get('company')}
|
||||
return list({v.get('company') for v in vacancies if v.get('company')})
|
||||
def extract_top_skills(vacancies: list[dict], top_n: int) -> list[tuple[str, int]]:
|
||||
all_skills = []
|
||||
for v in vacancies:
|
||||
all_skills.extend(v.get('skills', []))
|
||||
|
||||
skill_counts = Counter(all_skills)
|
||||
return skill_counts.most_common(top_n)
|
||||
def calculate_average_salary(vacancies: list[dict]) -> float:
|
||||
@ -33,17 +29,14 @@ def calculate_average_salary(vacancies: list[dict]) -> float:
|
||||
for v in vacancies:
|
||||
salary_from = v.get('salary_from')
|
||||
salary_to = v.get('salary_to')
|
||||
|
||||
if salary_from is not None and salary_to is not None:
|
||||
salaries.append((salary_from + salary_to) / 2)
|
||||
elif salary_from is not None:
|
||||
salaries.append(salary_from)
|
||||
elif salary_to is not None:
|
||||
salaries.append(salary_to)
|
||||
|
||||
if not salaries:
|
||||
return 0.0
|
||||
|
||||
return sum(salaries) / len(salaries)
|
||||
def group_by_company(vacancies: list[dict]) -> dict[str, int]:
|
||||
all_company = []
|
||||
@ -54,7 +47,6 @@ def group_by_company(vacancies: list[dict]) -> dict[str, int]:
|
||||
def format_vacancy_short(vacancy: dict) -> str:
|
||||
salary_from = vacancy.get('salary_from')
|
||||
salary_to = vacancy.get('salary_to')
|
||||
|
||||
if salary_from is not None and salary_to is not None:
|
||||
salary_str = f"от {salary_from} до {salary_to}"
|
||||
elif salary_from is not None:
|
||||
@ -63,32 +55,35 @@ def format_vacancy_short(vacancy: dict) -> str:
|
||||
salary_str = f"до {salary_to}"
|
||||
else:
|
||||
salary_str = "зарплата не указана"
|
||||
|
||||
return (f"ID {vacancy.get('id')}: {vacancy.get('title')} в {vacancy.get('company')}, "
|
||||
f"{vacancy.get('city')} — {salary_str}")
|
||||
f"{vacancy.get('city')} — {salary_str}\n")
|
||||
def save_filtered_results(vacancies: list[dict], filename: str) -> bool:
|
||||
return
|
||||
def interface():
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
print ("Your command:")
|
||||
print ("1. Load form json\n2. Filter by city\n3. Filter by skils\n4. Filter by salary")
|
||||
print ("5. Extract unique companies\n6. Extract top skills\n7. Calculate average salary")
|
||||
print ("8. Group by company\n9. Format vacancy short\n10. Save filtred results\n11. Exit")
|
||||
def user_chouse(user_input:int):
|
||||
match user_input:
|
||||
case 1:
|
||||
|
||||
return load_vacancies(input("Path for json: "))
|
||||
case 11:
|
||||
return
|
||||
case _:
|
||||
print ("Error uncorrecteble number")
|
||||
try:
|
||||
with open(filename,"w") as file:
|
||||
file.writelines(format_vacancy_short(x) for x in vacancies)
|
||||
return 0
|
||||
except:
|
||||
return 1
|
||||
def main():
|
||||
while (user_input != 11):
|
||||
interface()
|
||||
user_input = int(input("Chouse command: "))
|
||||
user_chouse(user_input)
|
||||
|
||||
main_list=load_vacancies(input("Write path for json:"))
|
||||
filered_vacancies = filter_by_city(main_list,input("Write city"))
|
||||
skils_list=[]
|
||||
for i in range(int(input("Write number of skills: "))):
|
||||
skils_list.append(input(f"Write №{i + 1} skill: "))
|
||||
filered_vacancies=filter_by_skills(filered_vacancies,skils_list)
|
||||
filered_vacancies = filter_by_salary(filered_vacancies,int(input("Write salary: ")))
|
||||
print("Уникальные компании: ", ", ".join(extract_unique_companies(filered_vacancies)))
|
||||
top_skills = extract_top_skills(filered_vacancies, 5)
|
||||
print(f"Топ-5 навыков:")
|
||||
for skill, count in top_skills:
|
||||
print(f" {skill}: {count} вакансий")
|
||||
print(f"\nСредняя зарплата: {calculate_average_salary(filered_vacancies):,.0f} руб.")
|
||||
for company, count in group_by_company(filered_vacancies).items():
|
||||
print(f" {company}: {count} вакансий")
|
||||
if(save_filtered_results(filered_vacancies,input("Write where to save"))):
|
||||
print("Check your path")
|
||||
else:
|
||||
print("Everything is fine, the file is saved")
|
||||
if __name__ =="__main__":
|
||||
#вход проги
|
||||
main()
|
||||
Loading…
Reference in New Issue
Block a user