Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Лабораторная работа 4/input.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
longitude,latitude,housing_median_age,total_rooms,total_bedrooms,population,households,median_income,median_house_value
-122.050000,37.370000,27.000000,3885.000000,661.000000,1537.000000,606.000000,6.608500,344700.000000
-118.300000,34.260000,43.000000,1510.000000,310.000000,809.000000,277.000000,3.599000,176500.000000
-117.810000,33.780000,27.000000,3589.000000,507.000000,1484.000000,495.000000,5.793400,270500.000000
-118.360000,33.820000,28.000000,67.000000,15.000000,49.000000,11.000000,6.135900,330000.000000
34 changes: 34 additions & 0 deletions Лабораторная работа 4/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"score": 0.0009456152645028281,
"weight": 1
},
{
"score": 0.00020640167757499364,
"weight": 1
},
{
"score": 0,
"weight": 1
},
{
"score": 1.6557065217391307,
"weight": 1
},
{
"score": 0,
"weight": 1
},
{
"score": 0.6066065217391303,
"weight": 1
},
{
"score": 0.03126181644071977,
"weight": 1
},
{
"score": 0.001253973281817707,
"weight": 1
}
]
46 changes: 46 additions & 0 deletions Лабораторная работа 4/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"longitude": "-122.050000",
"latitude": "37.370000",
"housing_median_age": "27.000000",
"total_rooms": "3885.000000",
"total_bedrooms": "661.000000",
"population": "1537.000000",
"households": "606.000000",
"median_income": "6.608500",
"median_house_value": "344700.000000"
},
{
"longitude": "-118.300000",
"latitude": "34.260000",
"housing_median_age": "43.000000",
"total_rooms": "1510.000000",
"total_bedrooms": "310.000000",
"population": "809.000000",
"households": "277.000000",
"median_income": "3.599000",
"median_house_value": "176500.000000"
},
{
"longitude": "-117.810000",
"latitude": "33.780000",
"housing_median_age": "27.000000",
"total_rooms": "3589.000000",
"total_bedrooms": "507.000000",
"population": "1484.000000",
"households": "495.000000",
"median_income": "5.793400",
"median_house_value": "270500.000000"
},
{
"longitude": "-118.360000",
"latitude": "33.820000",
"housing_median_age": "28.000000",
"total_rooms": "67.000000",
"total_bedrooms": "15.000000",
"population": "49.000000",
"households": "11.000000",
"median_income": "6.135900",
"median_house_value": "330000.000000"
}
]
13 changes: 13 additions & 0 deletions Лабораторная работа 4/task_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json


def task(path) -> float:
with open(path, 'r') as f:
data = json.load(f)

sum_of_products = sum([element["score"] * element["weight"] for element in data])

return round(sum_of_products, 3)


print(task("input.json"))
26 changes: 26 additions & 0 deletions Лабораторная работа 4/task_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import csv
import json


INPUT_FILENAME = "input.csv"
OUTPUT_FILENAME = "output.json"


def task() -> None:
data = []
with open(INPUT_FILENAME, 'r') as f:
reader = csv.DictReader(f)
for row in reader:
data.append(row)

with open(OUTPUT_FILENAME, 'w') as f:
json.dump(data, f, indent=4)


if __name__ == '__main__':
# Нужно для проверки
task()

with open(OUTPUT_FILENAME) as output_f:
for line in output_f:
print(line, end="")