Last active
February 15, 2025 06:46
-
-
Save derofim/396c512fded6204a7a264610ecd22964 to your computer and use it in GitHub Desktop.
py.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
import operator | |
import os | |
import os.path | |
import glob | |
from collections import Counter | |
import operator | |
import re | |
from os import listdir, walk | |
from os.path import isfile, isdir, join, getsize | |
textFile ='20170306_0708-comma_separated.csv' | |
print("our file: " + textFile) | |
def trim(line): | |
"docstring" | |
cleaned = line.lstrip().rstrip().replace('\n', '').replace('\r', '').replace('\t', '') | |
return cleaned | |
# Фамилия,Имя,"Учреждение (организация)",Отдел,"Адрес электронной почты",Состояние,"Тест начат",Завершено, | |
# "Затраченное время","Оценка/10,00","В. 1 /1,00","В. 2 /1,00","В. 3 /1,00","В. 4 /1,00","В. 5 /1,00","В. 6 /1,00","В. 7 /1,00","В. 8 /1,00","В. 9 /1,00","В. 10 /1,00" | |
#Апиравичюс,Татьяна,,,[email protected],Завершено,"8 Февраль 2017 15:51","8 Февраль 2017 16:24","33 мин. 5 сек.","8,00","1,00","1,00","0,00","1,00","1,00","1,00","1,00","1,00","1,00","0,00" | |
def replaceComma(line): | |
"docstring" | |
regex = re.compile(r',', re.IGNORECASE) | |
line = regex.sub('.', line) | |
return line | |
def workLine(line): | |
"docstring" | |
lineCombined = "" | |
words = re.split(r'"*"', (line)) | |
for word in words: | |
word = trim(word) | |
#print(word) | |
#regex = re.compile(r'\d+(,)\d+', re.IGNORECASE) | |
#word = regex.sub('.', word) | |
found = re.match(r"^.*\d+(,)\d+.*$", word) | |
if found: | |
ip = found.group() | |
#print(ip) | |
word = (replaceComma(word)) | |
word = trim(word) | |
if(len(word)): | |
#print(word) | |
lineCombined+=word | |
words1 = re.split(r',+', trim(word)) | |
for word1 in words1: | |
#if(len(word1)): | |
trim(word1) | |
#rint(word1) | |
return trim(lineCombined) | |
file1 = open(textFile, 'r', encoding="utf-8", newline='\n') | |
filedata = file1.readlines() | |
Zakon = 0 # 10 11 | |
EkPravo = 0 # 12 | |
Pedag = 0 # 13 14 | |
Psyxo = 0 # 15 16 | |
IKT = 0 # 17 18 19 | |
def countZero(listNums, A): | |
ret = 0 | |
for it in listNums: | |
val = float(A[it]) | |
if(val==0.0): | |
ret+=1 | |
return ret | |
marksCount = {} | |
def addDict(dict, key): | |
if(key in dict): | |
dict[key] = dict[key] + 1 | |
else: | |
dict[key] = 1 | |
return | |
def updateMarksCount(listNums, A): | |
for it in listNums: | |
val = int(float(A[it])) | |
addDict(marksCount, val) | |
return | |
def sumValsTotal(dict): | |
ret = 0 | |
for it in dict: | |
val = dict[it] | |
ret+=val | |
return ret | |
lineNum = 0 | |
for line in filedata: | |
if lineNum>0: | |
line = trim(line) | |
#print("=====") | |
line = workLine(line) | |
A = re.split(r',', trim(line)) | |
#print(str(len(A)) + ":" + str(A)) | |
IKT+=countZero({17,18,19}, A) | |
Psyxo+=countZero({15,16}, A) | |
Pedag+=countZero({13,14}, A) | |
EkPravo+=countZero({12}, A) | |
Zakon+=countZero({10,11}, A) | |
updateMarksCount({9},A) | |
lineNum+=1 | |
totalMarks = sumValsTotal(marksCount) | |
#print(str(marksCount) + " <=> Total sum of vals "+ str(totalMarks)) | |
for it in marksCount: | |
percentage = round(marksCount[it]/totalMarks*100, 2) | |
print(str(it) + " = " + str(percentage)+"%") | |
print("Num of zeros in IKT: " + str(IKT)) | |
print("Num of zeros in Psyxo: " + str(Psyxo)) | |
print("Num of zeros in Pedag: " + str(Pedag)) | |
print("Num of zeros in EkPravo: " + str(EkPravo)) | |
print("Num of zeros in Zakon: " + str(Zakon)) | |
#for line in filedata: | |
# #print(line) | |
# words = re.split(r'"*"', trim(line)) | |
# for word in words: | |
# #print(word)# | |
# regex = re.compile(r',', re.IGNORECASE) | |
# #word = regex.sub('.', trim(word)) | |
# #word = re.sub(r'(\d+)\,\d+', lambda m: format(float(m.group(1)),'.'), trim(word)) | |
# words1 = re.split(r',+', trim(word)) | |
# print(words1) | |
# for word1 in words1: | |
# if(len(word1)): | |
# trim(word1) | |
# #print(word1) | |
file1.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
our file: 20170306_0708-comma_separated.csv
8 = 21.43%
9 = 21.43%
10 = 39.29%
5 = 3.57%
7 = 14.29%
Num of zeros in IKT: 6
Num of zeros in Psyxo: 5
Num of zeros in Pedag: 4
Num of zeros in EkPravo: 6
Num of zeros in Zakon: 10