Documentation: OverTime
Overview
This is a web application consisting of a SvelteKit Frontend and a
Setting up UI
1.clone the given repository.
git clone https://github.com/VishnuSarathy/overtime.git
2.Install node modules.
npm install
3.You are set to run the project!!
npm run dev
Setting up MetaMask Extension
Install MetaMask extension on your browser from https://metamask.io/download/
Create a new wallet or import an existing one.
Go to the sign in page and click on Login with meta mask.
Documentation: Task Allocation Algorithm in WorkerTaskAllocation Smart Contract
Overview
The WorkerTaskAllocation smart contract facilitates the dynamic assignment of tasks to workers based on their availability, expertise, and the specific requirements of tasks. The contract manages tasks that can be either divisible or indivisible, and it ensures that tasks are allocated efficiently, respecting deadlines and dependencies.
Key Concepts
-
Worker: An entity that registers with the system, providing information such as available working hours, expertise level, minimum wage, and wallet address. Workers are assigned tasks based on these attributes.
-
Task: A unit of work that requires a certain amount of time and expertise to complete. Tasks can either be divisible (can be split among multiple workers) or indivisible (must be completed by a single worker). Tasks have deadlines, hourly wages, and dependencies on other tasks.
-
Dependencies: Tasks can depend on the completion of other tasks. A task cannot be started unless all its dependencies are completed.
-
Deadlines: Each task has a deadline by which it must be completed. The algorithm ensures that tasks are assigned to workers in a way that meets these deadlines.
Task Allocation Process
The task allocation process involves two main steps:
- Assignment of Indivisible Tasks
- Allocation of Divisible Tasks
1. Assignment of Indivisible Tasks
Indivisible tasks are assigned to workers who meet the following criteria:
- The worker has sufficient available hours to complete the task.
- The worker’s expertise level meets or exceeds the task’s requirement.
- The task’s hourly wage is greater than or equal to the worker’s minimum wage.
- The worker can complete the task before its deadline.
- All dependencies of the task are completed.
Steps:
- Iteration over Indivisible Tasks: The algorithm iterates over all registered workers and all indivisible tasks.
- Eligibility Check: For each worker-task pair, the algorithm checks whether the worker is eligible for the task based on the above criteria.
- Task Assignment: If the worker is eligible, the task is assigned to them, their available hours are reduced, and the task is marked as completed.
- Deregistration: If a worker’s available hours are exhausted, they are deregistered from the system.
Functions Used:
assignWorkerToIndivisibleTasks(address _workerAddress)deregisterWorker(address _workerAddress)
2. Allocation of Divisible Tasks
Divisible tasks can be split among multiple workers. The allocation algorithm ensures that each worker is assigned a portion of the task that matches their available hours, expertise level, and the task’s requirements.
Steps:
- Get Eligible Tasks: For each registered worker, the algorithm identifies tasks that the worker is eligible to work on.
- Determine Hours Workable: The algorithm calculates the maximum number of hours the worker can contribute to the task based on their availability and the task’s deadline.
- Assign Task Portion: The worker is assigned a portion of the task, and their available hours are reduced accordingly.
- Completion Check: If the task is fully allocated, it is marked as completed.
Functions Used:
allocateDivisibleTasks(address _workerAddress)getEligibleDivisibleTasks(address _workerAddress)sortTasksByExpertiseLevel(uint256[] memory taskIds)
Dependency Management
Tasks may have dependencies, meaning they cannot start until certain other tasks are completed. The algorithm ensures that:
- A task is not assigned until all its dependencies are completed.
- Dependencies are checked in both indivisible and divisible task allocations.
Functions Used:
dependenciesCompleted(uint256 _taskId)
Deadlines and Time Management
The algorithm considers deadlines to ensure that tasks are completed on time. Workers are only assigned tasks if they can complete them before the task’s deadline.
Time Constants:
SECONDS_PER_HOUR: Used to calculate the required completion time for tasks.SECONDS_PER_MINUTE: Used for finer-grained time management in specific cases.
Functionality:
- Workers’ availability is adjusted according to the tasks they are assigned.
- Deadlines are respected in both indivisible and divisible task assignments.
Payment Processing
After task completion, workers are paid according to the time they worked and the task’s hourly wage. Payments are made directly to the workers’ wallet addresses.
Functionality:
- The
payForTask(uint256 task_id)function is responsible for processing payments to workers once a task is completed.
Event Logging
Throughout the task allocation process, several events are emitted to track key actions:
WorkerRegistered: Emitted when a worker registers.TaskAdded: Emitted when a new task is added.TaskAssigned: Emitted when a task is assigned to a worker.TaskCompleted: Emitted when a task is completed.WorkerDeregistered: Emitted when a worker is deregistered.TaskDiscarded: Emitted when a task is discarded (e.g., due to missed deadlines or no eligible workers).
This algorithm ensures a fair and efficient distribution of tasks among workers while maintaining flexibility in handling both divisible and indivisible tasks. The approach balances workload, expertise, and deadlines to optimize task completion and worker satisfaction.