일련의 프로세스와 시작 시간 및 지속 시간을 나타내는 탭 구분 CSV 파일을 읽고 난 후 팬더를 사용하여 데이터 프레임을 만듭니다 . 그런 다음 사용자 입력에서 가져온 시간 슬라이스를 사용하여 프로세스의 소요 시간을 찾기 위해 단순화 된 라운드 로빈 형식의 스케줄링을 적용해야합니다.판다 데이터 프레임을위한 라운드 로빈 스케줄링
지금까지 CSV 파일을 읽고 레이블을 지정하고 올바르게 정렬 할 수있었습니다. 그러나 각 프로세스의 완료 시간을 찾기 위해 행을 반복하는 루프를 만들려고 할 때마다 막혔다.
같은 코드는 지금까지 보이는 : 샘플 CSV 파일을 감안할 때
# round robin
def rr():
docname = (sys.argv[1])
method = (sys.argv[2])
# creates a variable from the user input to define timeslice
timeslice = int(re.search(r'\d+', method).group())
# use pandas to create a 2-d data frame from tab delimited file, set column 0 (process names) to string, set column
# 1 & 2 (start time and duration, respectively) to integers
d = pd.read_csv(docname, delimiter="\t", header=None, dtype={'0': str, '1': np.int32, '2': np.int32})
# sort d into d1 by values of start times[1], ascending
d1 = d.sort_values(by=1)
# Create a 4th column, set to 0, for the Completion time
d1[3] = 0
# change column names
d1.columns = ['Process', 'Start', 'Duration', 'Completion']
# intialize counter
counter = 0
# if any values in column 'Duration' are above 0, continue the loop
while (d1['Duration']).any() > 0:
for index, row in d1.iterrows():
# if value in column 'Duration' > the timeslice, add the value of the timeslice to the current counter,
# subtract it from the the current value in column 'Duration'
if row.Duration > timeslice:
counter += timeslice
row.Duration -= timeslice
print(index, row.Duration)
# if value in column "Duration" <= the timeslice, add the current value of the row:Duration to the counter
# subtract the Duration from itself, to make it 0
# set row:Completion to the current counter, which is the completion time for the process
elif row.Duration <= timeslice and row.Duration != 0:
counter += row.Duration
row.Duration -= row.Duration
row.Completion = counter
print(index, row.Duration)
# otherwise, if the value in Duration is already 0, print that index, with the "Done" indicator
else:
print(index, "Done")
이 d1
이
Process Start Duration Completion
3 p4 0 280 0
0 p1 5 140 0
1 p2 14 75 0
2 p3 36 320 0
5 p6 40 0 0
4 p5 67 125 0
처럼 보이는 내가 timeslice = 70
내 코드를 실행하면, 내가의 무한 루프를 얻을 :
3 210
0 70
1 5
2 250
5 Done
4 55
3 210
0 70
1 5
2 250
5 Done
4 55
정확하게 루프를 반복하고있는 것처럼 보입니다. e, 그리고 무한히 되풀이하다. 그러나 print(d1['Completion'])
은 모두 0의 값을 제공합니다. 즉, 올바른 counter
값을 d1['Completion']
에 할당하지 않습니다. 그때 평균 처리 시간을 찾는 데 사용할 수
Process Start Duration Completion
3 p4 0 280 830
0 p1 5 140 490
1 p2 14 75 495
2 p3 36 320 940
5 p6 40 0 280
4 p5 67 125 620
:
이상적으로 Completion
값은 같은 timeslice=70
을 주어 자신의 해당 시간에 작성한다. 그러나 어떤 이유로, 내 반복은 한 번 반복 된 다음 끝없이 반복됩니다. while
과 for
명령문의 순서를 바꾸려고 시도했을 때, 0에 도달 할 때까지 반복적으로 각 행을 반복하고 잘못된 완료 시간을 제공합니다.
미리 감사드립니다.
당신은 실제로 목록의 데이터를 구문 분석 dataframe.Try의 각 행의 값을 수정하지 않는 한 다음 목록에서 그들을 조정한다. – Acepcs
프로세스 이름과 관련하여 구문 분석 된 데이터를 순서대로 유지할 수 있습니까? 나는 네가 무슨 말을하고 있는지 생각해 보았지만, 어느 쪽이 어떤 과정을 마쳤는지를 이야기 할 수 없었다. 나는 listessentially 완료 시간에 의해 정렬과 함께 끝났다. 죄송합니다, 나는 Python을 처음 사용하고 설명서를 읽는 것이 이해할 수있는 방식으로 설명 할 수 없었습니다. –