Advertisement
btyr

Untitled

Jul 17th, 2023 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. import datetime
  2. import random
  3. from googleapiclient.discovery import build
  4. from google.oauth2 import service_account
  5.  
  6. # Set up Google Calendar API credentials
  7. SERVICE_ACCOUNT_FILE = 'path/to/service_account_credentials.json'
  8. SCOPES = ['https://www.googleapis.com/auth/calendar']
  9.  
  10. # Define the rules and constraints for shift generation
  11. # Replace the placeholders with your specific rules
  12.  
  13. # Define the list of senior and scrub employees
  14. senior_employees = ['Čolak', 'Mažar', 'Rajsman', 'Uzun', 'Konosić', 'Pavlek', 'Bojčić', 'Prlić', 'Kljaković', 'Moguš']
  15. scrub_employees = ['Vučić', 'Mirčić', 'Vlatković', 'Vidović']
  16.  
  17. # Define the shifts and their corresponding rules
  18. shift_types = ['ORs', 'Afternoon', '24h', 'On call Emergency', 'On call Tx heart', 'On call Tx lung']
  19. shift_rules = {
  20. 'ORs': {
  21. 'exclude_shifts': ['24h', 'Afternoon', 'On call Emergency'],
  22. 'rooms': {
  23. 'ORs room 1': [],
  24. 'ORs room 2': [],
  25. 'ORs room 3': [],
  26. 'Kat Lab': [],
  27. 'JIL': []
  28. }
  29. },
  30. 'Afternoon': {
  31. 'exclude_shifts': ['24h', 'On call Emergency'],
  32. 'exclude_on_call': True,
  33. 'prioritize_last_24h': True
  34. },
  35. '24h': {
  36. 'max_shifts_per_month': 4,
  37. 'senior_scrub_together': True,
  38. 'friday_sunday_pattern': True,
  39. 'exclude_on_call': True
  40. },
  41. 'On call Emergency': {
  42. 'senior_only': True,
  43. 'exclude_shifts': ['24h'],
  44. 'exclude_after_24h': True,
  45. 'exclude_after_next_24h': True,
  46. 'exclude_afternoon': True
  47. },
  48. 'On call Tx heart': {
  49. 'exclude_shifts': ['24h']
  50. },
  51. 'On call Tx lung': {
  52. 'specific_employees': ['Konosić', 'Bojčić', 'Moguš', 'Prlić'],
  53. 'exclude_shifts': ['24h']
  54. }
  55. }
  56.  
  57. # Define the date range for generating shifts
  58. start_date = datetime.date(2023, 7, 1)
  59. end_date = datetime.date(2023, 7, 31)
  60.  
  61. def generate_shifts():
  62. shifts = []
  63.  
  64. current_date = start_date
  65.  
  66. while current_date <= end_date:
  67. shift_type = random.choice(shift_types)
  68. shift = {
  69. 'date': current_date,
  70. 'type': shift_type,
  71. 'employee': ''
  72. }
  73.  
  74. if shift_type == '24h':
  75. # Implement 24h shift rules
  76. pass
  77. elif shift_type == 'Afternoon':
  78. # Implement afternoon shift rules
  79. pass
  80. elif shift_type == 'ORs':
  81. # Implement ORs shift rules
  82. pass
  83. elif shift_type == 'On call Emergency':
  84. # Implement On call Emergency rules
  85. pass
  86. elif shift_type == 'On call Tx heart':
  87. # Implement On call Tx heart rules
  88. pass
  89. elif shift_type == 'On call Tx lung':
  90. # Implement On call Tx lung rules
  91. pass
  92.  
  93. shifts.append(shift)
  94. current_date += datetime.timedelta(days=1)
  95.  
  96. return shifts
  97.  
  98. def create_calendar_event(service, event_data):
  99. event = {
  100. 'summary': event_data['type'] + ' Shift',
  101. 'start': {
  102. 'date': str(event_data['date'])
  103. },
  104. 'end': {
  105. 'date': str(event_data['date'])
  106. }
  107. }
  108.  
  109. if event_data['type'] == 'ORs':
  110. room = random.choice(list(shift_rules['ORs']['rooms'].keys()))
  111. event['location'] = room
  112.  
  113. if event_data['employee']:
  114. event['description'] = 'Assigned Employee: ' + event_data['employee']
  115.  
  116. event = service.events().insert(calendarId='primary', body=event).execute()
  117. print('Event created:', event.get('htmlLink'))
  118.  
  119. def main():
  120. # Authenticate and connect to Google Calendar API
  121. credentials = service_account.Credentials.from_service_account_file(
  122. SERVICE_ACCOUNT_FILE, scopes=SCOPES)
  123. service = build('calendar', 'v3', credentials=credentials)
  124.  
  125. # Generate shifts
  126. shifts = generate_shifts()
  127.  
  128. # Create calendar events for the shifts
  129. for shift in shifts:
  130. create_calendar_event(service, shift)
  131.  
  132. if __name__ == '__main__':
  133. main()
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement