Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1.  
  2. code
  3. code
  4. 100%
  5. 11
  6. link copied to clipboard., anyone with the link can edit.
  7. def‌ ‌generate_roster(name_file_path,‌ ‌roster_file_path,‌ ‌year=19):‌ ‌
  8. ‌"""‌ ‌
  9. ‌Given‌ ‌a‌ ‌path‌ ‌to‌ ‌file‌ ‌with‌ ‌list‌ ‌of‌ ‌two‌ ‌names‌ ‌separated‌ ‌by‌ ‌space,‌ ‌
  10. ‌a‌ ‌path‌ ‌to‌ ‌file‌ ‌for‌ ‌output‌ ‌roster,‌ ‌and‌ ‌year‌ ‌(default‌ ‌=‌ ‌19),‌ ‌
  11. ‌Generate‌ ‌a‌ ‌roster‌ ‌as‌ ‌a‌ ‌TAB‌ ‌separated‌ ‌file‌ ‌of‌ ‌:‌ ‌
  12. ‌Last‌ ‌First‌ ‌ID‌ ‌
  13. ‌on‌ ‌each‌ ‌line,‌ ‌where‌ ‌ID‌ ‌=‌ ‌first.last.year‌ ‌
  14. ‌Ignore‌ ‌all‌ ‌lines‌ ‌that‌ ‌start‌ ‌with‌ ‌#‌ ‌
  15. ‌ ‌
  16. ‌:param‌ ‌name_file_path:‌ ‌relative‌ ‌path‌ ‌to‌ ‌file‌ ‌containing‌ ‌a‌ ‌list‌ ‌of‌ ‌names‌ ‌
  17. ‌:param‌ ‌roster_file_path:‌ ‌relative‌ ‌path‌ ‌to‌ ‌file‌ ‌to‌ ‌hold‌ ‌the‌ ‌output‌ ‌roster‌ ‌
  18. ‌:param‌ ‌year:‌ ‌year‌ ‌integer‌ ‌used‌ ‌to‌ ‌assign‌ ‌student‌ ‌IDs‌ ‌
  19. ‌:return:‌ ‌number‌ ‌of‌ ‌students‌ ‌in‌ ‌roster‌ ‌
  20. ‌"""‌ ‌
  21. ‌ ‌
  22. ‌pass‌ ‌
  23. ‌return‌ ‌-1‌ ‌
  24. def‌ ‌generate_expected_grades(roster_file_path,‌ ‌expected_grade_file_path,‌ ‌
  25. ‌class_mean,‌ ‌class_std_dev‌ ‌):‌ ‌
  26. ‌"""‌ ‌
  27. ‌Given‌ ‌class‌ ‌roster‌ ‌(Last‌ ‌First‌ ‌ID),‌ ‌generate‌ ‌an‌ ‌
  28. ‌file‌ ‌that‌ ‌randomly‌ ‌assigns‌ ‌an‌ ‌expected‌ ‌grade‌ ‌to‌ ‌each‌ ‌student‌ ‌
  29. ‌according‌ ‌to‌ ‌a‌ ‌Gaussian‌ ‌(normal)‌ ‌distribution‌ ‌of‌ ‌defined‌ ‌by‌ ‌
  30. ‌class_mean‌ ‌and‌ ‌class_std_deviation‌ ‌
  31. ‌If‌ ‌the‌ ‌sample‌ ‌is‌ ‌higher‌ ‌than‌ ‌100,‌ ‌re-sample.‌ ‌
  32. ‌If‌ ‌the‌ ‌sample‌ ‌is‌ ‌lower‌ ‌than‌ ‌0‌ ‌or‌ ‌5‌ ‌standard‌ ‌deviations‌ ‌below‌ ‌mean,‌ ‌
  33. ‌re-sample‌ ‌
  34. ‌:param‌ ‌roster_file_path:‌ ‌file‌ ‌containing‌ ‌class‌ ‌roster‌ ‌
  35. ‌:param‌ ‌expected_grade_file_path:‌ ‌output‌ ‌file‌ ‌containing‌ ‌ID‌ ‌and‌ ‌expected‌ ‌
  36. expected_grade_file_path‌ ‌of‌ ‌list‌ ‌of‌ ‌operations‌ ‌
  37. ‌:param‌ ‌class_mean:‌ ‌ideal‌ ‌mean‌ ‌for‌ ‌the‌ ‌class‌ ‌samples‌ ‌
  38. ‌:param‌ ‌class_std_deviation:‌ ‌ideal‌ ‌std_deviation‌ ‌for‌ ‌samples‌ ‌
  39. ‌:return:‌ ‌calculated‌ ‌median,‌ ‌mean,‌ ‌std_dev‌ ‌for‌ ‌all‌ ‌samples‌ ‌
  40. ‌"""‌ ‌
  41. ‌pass‌ ‌
  42. ‌return‌ ‌None,‌ ‌None,‌ ‌None‌ ‌
  43. """‌ ‌
  44. Simple‌ ‌output‌ ‌if‌ ‌you‌ ‌run‌ ‌as‌ ‌a‌ ‌script‌ ‌
  45. """‌ ‌
  46. if‌ ‌__name__‌ ‌==‌ ‌'__main__':‌ ‌
  47. ‌import‌ ‌os‌ ‌
  48. ‌num_students‌ ‌=‌ ‌generate_roster(os.path.join("data","short_names.txt"),‌ ‌
  49. ‌os.path.join("data","short_roster.csv"))‌ ‌
  50. ‌print("Generated‌ ‌",num_student,"‌ ‌IDs‌ ‌in‌ ‌roster")‌ ‌
  51. ‌median,‌ ‌mean,‌ ‌std_dev‌ ‌=‌ ‌generate_expected_grades(os.path.join("data","short_roster.csv"),‌ ‌
  52. ‌os.path.join("data","short_expected.csv"),‌ ‌
  53. ‌78.0,‌ ‌10.0)‌ ‌
  54. ‌print("Calculated‌ ‌median={}‌ ‌mean={}‌ ‌s.d.={}".format(median,‌ ‌mean,‌ ‌std_dev))‌ ‌
  55. def‌ ‌generate_letter_grades(expected_grade_file_path,‌ ‌
  56. ‌gpa_file_path‌ ‌):‌ ‌
  57. ‌"""‌ ‌
  58. ‌Given‌ ‌file‌ ‌containing‌ ‌ID‌ ‌and‌ ‌expected‌ ‌grade‌ ‌separated‌ ‌by‌ ‌TAB‌ ‌characters‌ ‌
  59. ‌Generate‌ ‌output‌ ‌file‌ ‌containing‌ ‌ID,‌ ‌expected‌ ‌grade‌ ‌(100‌ ‌scale),‌ ‌
  60. ‌comparable‌ ‌GPA‌ ‌(4.0‌ ‌scale),‌ ‌and‌ ‌letter‌ ‌grade‌ ‌separated‌ ‌by‌ ‌tabs.‌ ‌
  61. ‌For‌ ‌example,‌ ‌given‌ ‌
  62. ‌captain.chris.19‌ ‌78‌ ‌
  63. ‌which‌ ‌for‌ ‌our‌ ‌purposes‌ ‌is‌ ‌a‌ ‌C+,‌ ‌the‌ ‌output‌ ‌file‌ ‌should‌ ‌contain‌ ‌
  64. ‌captain.chris.19‌ ‌78‌ ‌2.3‌ ‌C+‌ ‌
  65. ‌:param‌ ‌expected_grade_file_path:‌ ‌output‌ ‌file‌ ‌containing‌ ‌ID‌ ‌and‌ ‌expected‌ ‌
  66. expected_grade_file_path‌ ‌of‌ ‌list‌ ‌of‌ ‌operations‌ ‌
  67. ‌:param‌ ‌gpa_file_path:‌ ‌file‌ ‌containing‌ ‌ID,‌ ‌grade,‌ ‌gpa,‌ ‌and‌ ‌letter‌ ‌grade‌ ‌
  68. ‌:return:‌ ‌None‌ ‌
  69. ‌"""‌ ‌
  70. """‌ ‌
  71. Simple‌ ‌output‌ ‌if‌ ‌you‌ ‌run‌ ‌as‌ ‌a‌ ‌script‌ ‌
  72. """‌ ‌
  73. if‌ ‌__name__‌ ‌==‌ ‌'__main__':‌ ‌
  74. ‌import‌ ‌os‌ ‌
  75. ‌print("Generated‌ ‌file‌ ‌with‌ ‌comparable‌ ‌letter‌ ‌grades‌ ‌...‌ ‌")‌ ‌
  76. ‌generate_letter_grades(os.path.join("data","short_expected.csv"),‌ ‌
  77. ‌os.path.join("data","short_letters.csv"))‌ ‌
  78. Toggle screen reader support
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement