Compare commits
10 Commits
ada25201b9
...
e9754677c9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9754677c9 | ||
|
|
73ecd7d386 | ||
|
|
2396d73b2f | ||
|
|
9c91448815 | ||
|
|
82b4b3094a | ||
|
|
aedebb3eba | ||
|
|
7555dc3319 | ||
|
|
72d5a28f16 | ||
|
|
ad95e00c84 | ||
|
|
b3f70c0c9d |
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
.venv/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
output.txt
|
||||
*.docx
|
||||
|
||||
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
|
||||
72
data/test.json
Normal file
72
data/test.json
Normal file
@ -0,0 +1,72 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Python разработчик",
|
||||
"company": "Яндекс",
|
||||
"city": "Москва",
|
||||
"salary_from": 150000,
|
||||
"salary_to": 200000,
|
||||
"skills": ["Python", "SQL", "Django", "PostgreSQL"],
|
||||
"published_at": "2024-01-15"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Data Engineer",
|
||||
"company": "Тинькофф",
|
||||
"city": "Москва",
|
||||
"salary_from": 180000,
|
||||
"salary_to": 250000,
|
||||
"skills": ["Python", "SQL", "Spark", "Airflow"],
|
||||
"published_at": "2024-01-20"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Backend Developer",
|
||||
"company": "Ozon",
|
||||
"city": "Санкт-Петербург",
|
||||
"salary_from": 130000,
|
||||
"salary_to": 170000,
|
||||
"skills": ["Python", "FastAPI", "MongoDB"],
|
||||
"published_at": "2024-01-18"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "Data Analyst",
|
||||
"company": "Яндекс",
|
||||
"city": "Москва",
|
||||
"salary_from": 140000,
|
||||
"salary_to": 180000,
|
||||
"skills": ["Python", "SQL", "Tableau"],
|
||||
"published_at": "2024-01-22"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Junior Python Developer",
|
||||
"company": "Сбер",
|
||||
"city": "Москва",
|
||||
"salary_from": 100000,
|
||||
"salary_to": 130000,
|
||||
"skills": ["Python", "SQL", "Git"],
|
||||
"published_at": "2024-01-25"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Senior Python Developer",
|
||||
"company": "Wildberries",
|
||||
"city": "Москва",
|
||||
"salary_from": 200000,
|
||||
"salary_to": 300000,
|
||||
"skills": ["Python", "SQL", "Kafka", "Kubernetes"],
|
||||
"published_at": "2024-01-28"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"title": "Full Stack Developer",
|
||||
"company": "Avito",
|
||||
"city": "Москва",
|
||||
"salary_from": 170000,
|
||||
"salary_to": 220000,
|
||||
"skills": ["Python", "JavaScript", "React", "SQL"],
|
||||
"published_at": "2024-01-30"
|
||||
}
|
||||
]
|
||||
0
requirements.txt
Normal file
0
requirements.txt
Normal file
0
results/answer.csv
Normal file
0
results/answer.csv
Normal file
|
|
@ -1,17 +1,89 @@
|
||||
import json
|
||||
from typing import List, Dict
|
||||
def load_vacancies(filepath: str) -> List[Dict]:
|
||||
from collections import Counter
|
||||
def load_vacancies(filepath: str) -> list[dict]:
|
||||
try:
|
||||
with open(filepath,"r") as file:
|
||||
return json.load(file)
|
||||
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_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_from')> min_salary]
|
||||
def extract_unique_companies(vacancies: list[dict]) -> list[str]:
|
||||
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:
|
||||
if not vacancies:
|
||||
return 0.0
|
||||
else:
|
||||
salaries = []
|
||||
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 = []
|
||||
for v in vacancies:
|
||||
all_company.append(v.get('company'))
|
||||
company_count = Counter(all_company)
|
||||
return company_count
|
||||
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:
|
||||
salary_str = f"от {salary_from}"
|
||||
elif salary_to is not None:
|
||||
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}\n")
|
||||
def save_filtered_results(vacancies: list[dict], filename: str) -> bool:
|
||||
try:
|
||||
with open(filename,"w") as file:
|
||||
file.writelines(format_vacancy_short(x) for x in vacancies)
|
||||
return 0
|
||||
except:
|
||||
return 1
|
||||
def main():
|
||||
print("Hello World")
|
||||
|
||||
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