Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- import random
- from googleapiclient.discovery import build
- from google.oauth2 import service_account
- # Set up Google Calendar API credentials
- SERVICE_ACCOUNT_FILE = 'path/to/service_account_credentials.json'
- SCOPES = ['https://www.googleapis.com/auth/calendar']
- # Define the rules and constraints for shift generation
- # Replace the placeholders with your specific rules
- # Define the list of senior and scrub employees
- senior_employees = ['Čolak', 'Mažar', 'Rajsman', 'Uzun', 'Konosić', 'Pavlek', 'Bojčić', 'Prlić', 'Kljaković', 'Moguš']
- scrub_employees = ['Vučić', 'Mirčić', 'Vlatković', 'Vidović']
- # Define the shifts and their corresponding rules
- shift_types = ['ORs', 'Afternoon', '24h', 'On call Emergency', 'On call Tx heart', 'On call Tx lung']
- shift_rules = {
- 'ORs': {
- 'exclude_shifts': ['24h', 'Afternoon', 'On call Emergency'],
- 'rooms': {
- 'ORs room 1': [],
- 'ORs room 2': [],
- 'ORs room 3': [],
- 'Kat Lab': [],
- 'JIL': []
- }
- },
- 'Afternoon': {
- 'exclude_shifts': ['24h', 'On call Emergency'],
- 'exclude_on_call': True,
- 'prioritize_last_24h': True
- },
- '24h': {
- 'max_shifts_per_month': 4,
- 'senior_scrub_together': True,
- 'friday_sunday_pattern': True,
- 'exclude_on_call': True
- },
- 'On call Emergency': {
- 'senior_only': True,
- 'exclude_shifts': ['24h'],
- 'exclude_after_24h': True,
- 'exclude_after_next_24h': True,
- 'exclude_afternoon': True
- },
- 'On call Tx heart': {
- 'exclude_shifts': ['24h']
- },
- 'On call Tx lung': {
- 'specific_employees': ['Konosić', 'Bojčić', 'Moguš', 'Prlić'],
- 'exclude_shifts': ['24h']
- }
- }
- # Define the date range for generating shifts
- start_date = datetime.date(2023, 7, 1)
- end_date = datetime.date(2023, 7, 31)
- def generate_shifts():
- shifts = []
- current_date = start_date
- while current_date <= end_date:
- shift_type = random.choice(shift_types)
- shift = {
- 'date': current_date,
- 'type': shift_type,
- 'employee': ''
- }
- if shift_type == '24h':
- # Implement 24h shift rules
- pass
- elif shift_type == 'Afternoon':
- # Implement afternoon shift rules
- pass
- elif shift_type == 'ORs':
- # Implement ORs shift rules
- pass
- elif shift_type == 'On call Emergency':
- # Implement On call Emergency rules
- pass
- elif shift_type == 'On call Tx heart':
- # Implement On call Tx heart rules
- pass
- elif shift_type == 'On call Tx lung':
- # Implement On call Tx lung rules
- pass
- shifts.append(shift)
- current_date += datetime.timedelta(days=1)
- return shifts
- def create_calendar_event(service, event_data):
- event = {
- 'summary': event_data['type'] + ' Shift',
- 'start': {
- 'date': str(event_data['date'])
- },
- 'end': {
- 'date': str(event_data['date'])
- }
- }
- if event_data['type'] == 'ORs':
- room = random.choice(list(shift_rules['ORs']['rooms'].keys()))
- event['location'] = room
- if event_data['employee']:
- event['description'] = 'Assigned Employee: ' + event_data['employee']
- event = service.events().insert(calendarId='primary', body=event).execute()
- print('Event created:', event.get('htmlLink'))
- def main():
- # Authenticate and connect to Google Calendar API
- credentials = service_account.Credentials.from_service_account_file(
- SERVICE_ACCOUNT_FILE, scopes=SCOPES)
- service = build('calendar', 'v3', credentials=credentials)
- # Generate shifts
- shifts = generate_shifts()
- # Create calendar events for the shifts
- for shift in shifts:
- create_calendar_event(service, shift)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement