-
Notifications
You must be signed in to change notification settings - Fork 0
/
rock_grader.py
32 lines (24 loc) · 1.08 KB
/
rock_grader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pandas as pd
from typing import List
class RockGrader:
def __init__(self):
df = pd.read_csv('./data/rock_grade_label.csv', usecols=['position', 'grade'])
self.positions = df['position'].tolist()
self.grades = df['grade'].tolist()
def grade(self, position: float):
for i, value in enumerate(self.positions):
if position <= value:
return ((self.grades[i] - self.grades[i - 1]) / (self.positions[i] - self.positions[i - 1]) *
(position - self.positions[i])) + self.grades[i]
def grade_to_csv(self, positions: List[float]):
grades = []
for position in positions:
grades.append(self.grade(position))
data = {'position': positions, 'grade': grades}
df = pd.DataFrame(data)
df.to_csv('./data/youngdeok_rock_grade.csv', index_label="id")
if __name__ == '__main__':
df = pd.read_csv('./data/youngdeok_data.csv', usecols=['position'])
positions = df['position'].tolist()
rock_grader = RockGrader()
rock_grader.grade_to_csv(positions)