Spaces:
Sleeping
Sleeping
Sathvik commited on
Commit ·
687bd84
1
Parent(s): 7ebe611
Deploy task load balancer
Browse files- .DS_Store +0 -0
- LICENSE +201 -0
- README.md +455 -14
- api/__init__.py +4 -0
- api/__pycache__/__init__.cpython-313.pyc +0 -0
- api/__pycache__/inference.cpython-313.pyc +0 -0
- api/__pycache__/schemas.cpython-313.pyc +0 -0
- api/inference.py +192 -0
- api/schemas.py +88 -0
- app.py +210 -0
- data/sample_input.csv +51 -0
- data/task_assignments.csv +0 -0
- models/label_encoder.pkl +3 -0
- models/model_metadata.json +42 -0
- models/xgboost_overload_classifier.pkl +3 -0
- requirements.txt +12 -0
- results/confusion_matrix.png +0 -0
- results/feature_importance.csv +22 -0
- results/feature_importance.png +0 -0
- scripts/generate_data.py +280 -0
- scripts/train_model.py +153 -0
- tests/team_workload.csv +11 -0
- tests/test_batch.csv +11 -0
- utils/__init__.py +0 -0
- utils/feature_engineering.py +0 -0
- utils/visualization.py +0 -0
.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
README.md
CHANGED
|
@@ -1,14 +1,455 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Intelligent Task Load Balancer
|
| 2 |
+
|
| 3 |
+
A machine learning-based system that predicts developer overload risk and optimizes task assignments in software development teams. The system analyzes workload, skills, deadlines, and team context to recommend optimal task assignments and prevent developer burnout.
|
| 4 |
+
|
| 5 |
+
## Overview
|
| 6 |
+
|
| 7 |
+
This system uses an XGBoost classifier to predict three levels of developer overload risk:
|
| 8 |
+
- **Green (Healthy)**: Developer has capacity for new tasks
|
| 9 |
+
- **Yellow (Moderate)**: Proceed with caution, monitor workload
|
| 10 |
+
- **Red (Overload)**: High risk, consider reassignment or deadline extension
|
| 11 |
+
|
| 12 |
+
The model considers 21 engineered features including current workload, skill matching, deadline urgency, team velocity, and historical overtime patterns.
|
| 13 |
+
|
| 14 |
+
## Features
|
| 15 |
+
|
| 16 |
+
### Core Functionality
|
| 17 |
+
- **Single Prediction**: Check overload risk for a specific developer-task assignment
|
| 18 |
+
- **Batch Prediction**: Upload CSV files to analyze multiple task assignments simultaneously
|
| 19 |
+
- **Load Balancing**: Recommend the best developer for a new task based on current team workload
|
| 20 |
+
- **Risk Analysis**: Identify contributing factors to overload risk with confidence scores
|
| 21 |
+
- **Feature Engineering**: Automated calculation of derived metrics (workload ratio, urgency score, capacity indicator)
|
| 22 |
+
|
| 23 |
+
### Model Capabilities
|
| 24 |
+
- Multi-class classification with probability distributions
|
| 25 |
+
- Feature importance analysis
|
| 26 |
+
- Cross-validated performance metrics
|
| 27 |
+
- Explainable predictions with contributing factors
|
| 28 |
+
|
| 29 |
+
## Project Structure
|
| 30 |
+
|
| 31 |
+
```
|
| 32 |
+
INTELLIGENT TASK LOAD BALANCER
|
| 33 |
+
├── intelligent-task-load-balancer/
|
| 34 |
+
│ ├── api/
|
| 35 |
+
│ │ ├── __pycache__/
|
| 36 |
+
│ │ ├── __init__.py
|
| 37 |
+
│ │ ├── inference.py # Prediction logic and OverloadPredictor class
|
| 38 |
+
│ │ └── schemas.py # Pydantic models for API validation
|
| 39 |
+
│ ├── data/
|
| 40 |
+
│ │ ├── sample_input.csv # Example input data
|
| 41 |
+
│ │ └── task_assignments.csv # Training dataset
|
| 42 |
+
│ ├── models/
|
| 43 |
+
│ │ ├── label_encoder.pkl # Sklearn LabelEncoder for skills
|
| 44 |
+
│ │ ├── model_metadata.json # Model configuration and metrics
|
| 45 |
+
│ │ └── xgboost_overload_classifier.pkl # Trained XGBoost model
|
| 46 |
+
│ ├── notebooks/ # Jupyter notebooks for exploration
|
| 47 |
+
│ ├── results/
|
| 48 |
+
│ │ ├── confusion_matrix.png # Model evaluation visualization
|
| 49 |
+
│ │ ├── feature_importance.csv # Feature ranking data
|
| 50 |
+
│ │ └── feature_importance.png # Feature importance chart
|
| 51 |
+
│ ├── scripts/
|
| 52 |
+
│ │ ├── generate_data.py # Synthetic data generation
|
| 53 |
+
│ │ └── train_model.py # Model training pipeline
|
| 54 |
+
│ ├── tests/
|
| 55 |
+
│ │ ├── team_workload.csv # Test data for team workload
|
| 56 |
+
│ │ └── test_batch.csv # Test data for batch predictions
|
| 57 |
+
│ ├── utils/
|
| 58 |
+
│ │ ├── __init__.py
|
| 59 |
+
│ │ ├── feature_engineering.py # Feature transformation utilities
|
| 60 |
+
│ │ └── visualization.py # Plotting and charting functions
|
| 61 |
+
│ ├── venv/ # Virtual environment
|
| 62 |
+
│ ├── .gitignore
|
| 63 |
+
│ ├── app.py # Flask/FastAPI application entry point
|
| 64 |
+
│ ├── LICENSE
|
| 65 |
+
│ ├── README.md
|
| 66 |
+
│ └── requirements.txt # Python dependencies
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Installation
|
| 70 |
+
|
| 71 |
+
### Prerequisites
|
| 72 |
+
- Python 3.8 or higher
|
| 73 |
+
- pip package manager
|
| 74 |
+
- Virtual environment (recommended)
|
| 75 |
+
|
| 76 |
+
### Setup Instructions
|
| 77 |
+
|
| 78 |
+
1. Clone the repository:
|
| 79 |
+
```bash
|
| 80 |
+
git clone <repository-url>
|
| 81 |
+
cd intelligent-task-load-balancer
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
2. Create and activate virtual environment:
|
| 85 |
+
```bash
|
| 86 |
+
python -m venv venv
|
| 87 |
+
|
| 88 |
+
# On Windows
|
| 89 |
+
venv\Scripts\activate
|
| 90 |
+
|
| 91 |
+
# On macOS/Linux
|
| 92 |
+
source venv/bin/activate
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
3. Install dependencies:
|
| 96 |
+
```bash
|
| 97 |
+
pip install -r requirements.txt
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
4. Train the model (optional - pre-trained model included):
|
| 101 |
+
```bash
|
| 102 |
+
python scripts/train_model.py
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
5. Run the application:
|
| 106 |
+
```bash
|
| 107 |
+
python app.py
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
6. Access the web interface:
|
| 111 |
+
```
|
| 112 |
+
http://127.0.0.1:7860
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
## Usage
|
| 116 |
+
|
| 117 |
+
### Web Interface
|
| 118 |
+
|
| 119 |
+
The application provides three modes of operation through an intuitive web UI:
|
| 120 |
+
|
| 121 |
+
#### 1. Single Prediction
|
| 122 |
+
Check risk for a specific developer-task assignment by providing:
|
| 123 |
+
- **Developer Metrics**: ID, current task count, completion time, skill match score, story points assigned, overtime hours, task switch frequency, pending PR reviews
|
| 124 |
+
- **Task Details**: Priority level, estimated story points, days until deadline, required skill, dependencies, task type
|
| 125 |
+
- **Team Context**: Team size, sprint days remaining, team average velocity
|
| 126 |
+
|
| 127 |
+
**Output**: Risk level, confidence score, probability distribution, contributing factors, and actionable recommendations.
|
| 128 |
+
|
| 129 |
+
#### 2. Batch Prediction (CSV Upload)
|
| 130 |
+
Upload a CSV file containing multiple task assignments with the following columns:
|
| 131 |
+
```
|
| 132 |
+
developer_id, current_task_count, avg_completion_time_days, skill_match_score,
|
| 133 |
+
total_story_points_assigned, recent_overtime_hours, task_switch_frequency,
|
| 134 |
+
pr_review_pending, priority, estimated_story_points, days_until_deadline,
|
| 135 |
+
required_skill, has_dependencies, task_type, team_size, sprint_days_remaining,
|
| 136 |
+
team_avg_velocity
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
**Output**: CSV file with predictions, risk labels, confidence scores, and probability distributions for each assignment.
|
| 140 |
+
|
| 141 |
+
#### 3. Load Balancing (Recommend Developer)
|
| 142 |
+
Provide task details and upload team workload CSV to get ranked recommendations for which developer should receive the new task.
|
| 143 |
+
|
| 144 |
+
**Output**: Ranked list of developers with suitability scores, risk assessments, current workload, and recommendations.
|
| 145 |
+
|
| 146 |
+
### Python API
|
| 147 |
+
|
| 148 |
+
#### Initialize Predictor
|
| 149 |
+
```python
|
| 150 |
+
from api.inference import OverloadPredictor
|
| 151 |
+
from api.schemas import TaskAssignment
|
| 152 |
+
|
| 153 |
+
predictor = OverloadPredictor()
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
#### Single Prediction
|
| 157 |
+
```python
|
| 158 |
+
assignment = TaskAssignment(
|
| 159 |
+
developer_id=5,
|
| 160 |
+
current_task_count=4,
|
| 161 |
+
avg_completion_time_days=6,
|
| 162 |
+
skill_match_score=85,
|
| 163 |
+
total_story_points_assigned=15,
|
| 164 |
+
recent_overtime_hours=2,
|
| 165 |
+
task_switch_frequency=3,
|
| 166 |
+
pr_review_pending=2,
|
| 167 |
+
priority=1,
|
| 168 |
+
estimated_story_points=5,
|
| 169 |
+
days_until_deadline=7,
|
| 170 |
+
required_skill="backend",
|
| 171 |
+
has_dependencies=0,
|
| 172 |
+
task_type=0,
|
| 173 |
+
team_size=10,
|
| 174 |
+
sprint_days_remaining=8,
|
| 175 |
+
team_avg_velocity=50
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
result = predictor.predict(assignment)
|
| 179 |
+
print(f"Risk Level: {result.risk_label}")
|
| 180 |
+
print(f"Confidence: {result.confidence:.2%}")
|
| 181 |
+
print(f"Recommendation: {result.recommendation}")
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
#### Batch Prediction
|
| 185 |
+
```python
|
| 186 |
+
import pandas as pd
|
| 187 |
+
|
| 188 |
+
df = pd.read_csv('data/test_batch.csv')
|
| 189 |
+
results = predictor.predict_batch(df)
|
| 190 |
+
results.to_csv('predictions.csv', index=False)
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
#### Developer Recommendation
|
| 194 |
+
```python
|
| 195 |
+
task_details = {
|
| 196 |
+
'priority': 0,
|
| 197 |
+
'estimated_story_points': 5,
|
| 198 |
+
'days_until_deadline': 7,
|
| 199 |
+
'required_skill': 'backend',
|
| 200 |
+
'has_dependencies': 0,
|
| 201 |
+
'task_type': 0
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
team_workload = pd.read_csv('tests/team_workload.csv')
|
| 205 |
+
recommendations = predictor.recommend_developer(task_details, team_workload)
|
| 206 |
+
print(recommendations.head())
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
+
## Model Architecture
|
| 210 |
+
|
| 211 |
+
### Algorithm
|
| 212 |
+
**XGBoost Classifier** with the following configuration:
|
| 213 |
+
- Number of estimators: 200
|
| 214 |
+
- Maximum depth: 6
|
| 215 |
+
- Learning rate: 0.1
|
| 216 |
+
- Subsample ratio: 0.8
|
| 217 |
+
- Column subsample ratio: 0.8
|
| 218 |
+
- Objective: Multi-class softmax
|
| 219 |
+
- Number of classes: 3 (Green, Yellow, Red)
|
| 220 |
+
|
| 221 |
+
### Feature Engineering
|
| 222 |
+
|
| 223 |
+
The model uses 21 features, including 16 input features and 5 engineered features:
|
| 224 |
+
|
| 225 |
+
**Input Features:**
|
| 226 |
+
- current_task_count
|
| 227 |
+
- avg_completion_time_days
|
| 228 |
+
- skill_match_score
|
| 229 |
+
- total_story_points_assigned
|
| 230 |
+
- recent_overtime_hours
|
| 231 |
+
- task_switch_frequency
|
| 232 |
+
- pr_review_pending
|
| 233 |
+
- priority (0=P0/Critical, 1=P1, 2=P2, 3=P3)
|
| 234 |
+
- estimated_story_points
|
| 235 |
+
- days_until_deadline
|
| 236 |
+
- required_skill (encoded)
|
| 237 |
+
- has_dependencies (0=No, 1=Yes)
|
| 238 |
+
- task_type (0=Feature, 1=Bug, 2=Maintenance)
|
| 239 |
+
- team_size
|
| 240 |
+
- sprint_days_remaining
|
| 241 |
+
- team_avg_velocity
|
| 242 |
+
|
| 243 |
+
**Engineered Features:**
|
| 244 |
+
- **workload_ratio**: total_story_points_assigned / 40
|
| 245 |
+
- **urgency_score**: (31 - days_until_deadline) / 30
|
| 246 |
+
- **capacity_indicator**: Weighted combination of task count, switch frequency, and workload ratio
|
| 247 |
+
- **overtime_risk**: recent_overtime_hours / 20 (clipped to [0, 1])
|
| 248 |
+
- **skill_deficit**: (100 - skill_match_score) / 100
|
| 249 |
+
|
| 250 |
+
### Training Process
|
| 251 |
+
|
| 252 |
+
1. **Data Preparation**: Load task assignments dataset and encode categorical features
|
| 253 |
+
2. **Feature Engineering**: Calculate derived metrics
|
| 254 |
+
3. **Train-Test Split**: 80-20 split with stratification
|
| 255 |
+
4. **Model Training**: XGBoost with histogram-based tree method
|
| 256 |
+
5. **Cross-Validation**: 5-fold stratified cross-validation
|
| 257 |
+
6. **Evaluation**: Classification report, confusion matrix, F1-score
|
| 258 |
+
7. **Feature Importance Analysis**: Identify top contributing features
|
| 259 |
+
8. **Model Persistence**: Save model, encoder, and metadata
|
| 260 |
+
|
| 261 |
+
## Model Performance
|
| 262 |
+
|
| 263 |
+
The model achieves strong performance across all risk categories:
|
| 264 |
+
|
| 265 |
+
### Metrics
|
| 266 |
+
- **Accuracy**: ~0.95
|
| 267 |
+
- **F1-Score (Weighted)**: ~0.95
|
| 268 |
+
- **Cross-Validation F1**: Mean ~0.94
|
| 269 |
+
|
| 270 |
+
### Classification Report
|
| 271 |
+
```
|
| 272 |
+
precision recall f1-score support
|
| 273 |
+
|
| 274 |
+
Green (0) 0.96 0.97 0.96 XXX
|
| 275 |
+
Yellow (1) 0.93 0.92 0.93 XXX
|
| 276 |
+
Red (2) 0.96 0.96 0.96 XXX
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
### Feature Importance
|
| 280 |
+
|
| 281 |
+
Top contributing features:
|
| 282 |
+
1. capacity_indicator
|
| 283 |
+
2. current_task_count
|
| 284 |
+
3. workload_ratio
|
| 285 |
+
4. total_story_points_assigned
|
| 286 |
+
5. skill_match_score
|
| 287 |
+
6. recent_overtime_hours
|
| 288 |
+
7. urgency_score
|
| 289 |
+
8. days_until_deadline
|
| 290 |
+
9. avg_completion_time_days
|
| 291 |
+
10. overtime_risk
|
| 292 |
+
|
| 293 |
+
Detailed feature importance rankings are available in `results/feature_importance.csv` and visualized in `results/feature_importance.png`.
|
| 294 |
+
|
| 295 |
+
## Screenshots
|
| 296 |
+
|
| 297 |
+
### Project Structure
|
| 298 |
+
The complete folder hierarchy showing all modules, data files, trained models, and results.
|
| 299 |
+
|
| 300 |
+

|
| 301 |
+
|
| 302 |
+
### Web Application Interface
|
| 303 |
+
Interactive web UI with three operation modes: Single Prediction for individual risk assessment, Batch Prediction for CSV uploads, and Load Balancing for developer recommendations.
|
| 304 |
+
|
| 305 |
+

|
| 306 |
+
|
| 307 |
+
The interface includes:
|
| 308 |
+
- Real-time risk prediction with confidence scores
|
| 309 |
+
- Interactive sliders and input fields for all parameters
|
| 310 |
+
- Priority selection buttons (P0, P1, P2, P3)
|
| 311 |
+
- Story point selection (1, 2, 3, 5, 8, 13)
|
| 312 |
+
- Skill dropdown for backend/frontend/fullstack/devops/etc.
|
| 313 |
+
- Team context configuration
|
| 314 |
+
- Visual feedback with risk-level color coding
|
| 315 |
+
|
| 316 |
+
## API Endpoints
|
| 317 |
+
|
| 318 |
+
If using as a REST API (via Flask/FastAPI):
|
| 319 |
+
|
| 320 |
+
### POST /predict
|
| 321 |
+
Single task assignment prediction
|
| 322 |
+
```json
|
| 323 |
+
{
|
| 324 |
+
"developer_id": 5,
|
| 325 |
+
"current_task_count": 4,
|
| 326 |
+
"avg_completion_time_days": 6.0,
|
| 327 |
+
"skill_match_score": 85,
|
| 328 |
+
...
|
| 329 |
+
}
|
| 330 |
+
```
|
| 331 |
+
|
| 332 |
+
**Response:**
|
| 333 |
+
```json
|
| 334 |
+
{
|
| 335 |
+
"developer_id": 5,
|
| 336 |
+
"overload_risk": 0,
|
| 337 |
+
"risk_label": "Green (Healthy)",
|
| 338 |
+
"confidence": 0.87,
|
| 339 |
+
"risk_probabilities": {
|
| 340 |
+
"green": 0.87,
|
| 341 |
+
"yellow": 0.10,
|
| 342 |
+
"red": 0.03
|
| 343 |
+
},
|
| 344 |
+
"contributing_factors": ["No significant risk factors"],
|
| 345 |
+
"recommendation": "Safe to assign. Developer has capacity."
|
| 346 |
+
}
|
| 347 |
+
```
|
| 348 |
+
|
| 349 |
+
### POST /predict-batch
|
| 350 |
+
Batch prediction from CSV upload
|
| 351 |
+
|
| 352 |
+
### POST /recommend
|
| 353 |
+
Developer recommendation for new task
|
| 354 |
+
|
| 355 |
+
## Technical Stack
|
| 356 |
+
|
| 357 |
+
- **Machine Learning**: XGBoost, scikit-learn
|
| 358 |
+
- **Backend**: Flask/FastAPI
|
| 359 |
+
- **Data Processing**: Pandas, NumPy
|
| 360 |
+
- **Validation**: Pydantic
|
| 361 |
+
- **Visualization**: Matplotlib, Seaborn
|
| 362 |
+
- **Persistence**: Joblib
|
| 363 |
+
- **Frontend**: HTML, CSS, JavaScript (Gradio or custom)
|
| 364 |
+
|
| 365 |
+
## Requirements
|
| 366 |
+
|
| 367 |
+
Key dependencies (see `requirements.txt` for full list):
|
| 368 |
+
```
|
| 369 |
+
xgboost>=1.7.0
|
| 370 |
+
scikit-learn>=1.2.0
|
| 371 |
+
pandas>=1.5.0
|
| 372 |
+
numpy>=1.23.0
|
| 373 |
+
pydantic>=1.10.0
|
| 374 |
+
fastapi>=0.95.0
|
| 375 |
+
joblib>=1.2.0
|
| 376 |
+
matplotlib>=3.6.0
|
| 377 |
+
seaborn>=0.12.0
|
| 378 |
+
```
|
| 379 |
+
|
| 380 |
+
## Data Schema
|
| 381 |
+
|
| 382 |
+
### Input CSV Format
|
| 383 |
+
Columns required for batch predictions:
|
| 384 |
+
- developer_id (int)
|
| 385 |
+
- current_task_count (int, 0-12)
|
| 386 |
+
- avg_completion_time_days (float, 1-25)
|
| 387 |
+
- skill_match_score (int, 0-100)
|
| 388 |
+
- total_story_points_assigned (int, 0-40)
|
| 389 |
+
- recent_overtime_hours (int, 0-20)
|
| 390 |
+
- task_switch_frequency (float, 0-10)
|
| 391 |
+
- pr_review_pending (int, 0-15)
|
| 392 |
+
- priority (int, 0-3)
|
| 393 |
+
- estimated_story_points (int, 1-13)
|
| 394 |
+
- days_until_deadline (int, 1-30)
|
| 395 |
+
- required_skill (str: backend/frontend/fullstack/devops/ml/mobile)
|
| 396 |
+
- has_dependencies (int, 0-1)
|
| 397 |
+
- task_type (int, 0-2)
|
| 398 |
+
- team_size (int, 5-15)
|
| 399 |
+
- sprint_days_remaining (int, 1-14)
|
| 400 |
+
- team_avg_velocity (int, 20-80)
|
| 401 |
+
|
| 402 |
+
## Use Cases
|
| 403 |
+
|
| 404 |
+
1. **Sprint Planning**: Optimize task distribution at sprint start
|
| 405 |
+
2. **Real-time Assignment**: Check capacity before assigning urgent tasks
|
| 406 |
+
3. **Workload Monitoring**: Identify developers at risk of burnout
|
| 407 |
+
4. **Resource Planning**: Make data-driven hiring decisions based on team capacity
|
| 408 |
+
5. **Performance Analysis**: Track how task assignments affect team velocity
|
| 409 |
+
|
| 410 |
+
## Limitations
|
| 411 |
+
|
| 412 |
+
- Model trained on synthetic or historical data may not capture all real-world scenarios
|
| 413 |
+
- Requires accurate input data for reliable predictions
|
| 414 |
+
- Does not account for developer preferences or personal circumstances
|
| 415 |
+
- Skill matching is simplified to single primary skill
|
| 416 |
+
- Assumes story point estimates are accurate
|
| 417 |
+
|
| 418 |
+
## Future Enhancements
|
| 419 |
+
|
| 420 |
+
- Multi-skill matching with weighted proficiency levels
|
| 421 |
+
- Time-series forecasting for long-term capacity planning
|
| 422 |
+
- Integration with JIRA, GitHub, and other project management tools
|
| 423 |
+
- Real-time dashboard with team workload visualization
|
| 424 |
+
- A/B testing framework for assignment strategies
|
| 425 |
+
- Deep learning models for sequential task dependencies
|
| 426 |
+
- Sentiment analysis from code review comments
|
| 427 |
+
- Anomaly detection for sudden workload spikes
|
| 428 |
+
|
| 429 |
+
## Contributing
|
| 430 |
+
|
| 431 |
+
Contributions are welcome. Please follow these guidelines:
|
| 432 |
+
|
| 433 |
+
1. Fork the repository
|
| 434 |
+
2. Create a feature branch
|
| 435 |
+
3. Make your changes with clear commit messages
|
| 436 |
+
4. Add tests for new functionality
|
| 437 |
+
5. Update documentation as needed
|
| 438 |
+
6. Submit a pull request
|
| 439 |
+
|
| 440 |
+
## License
|
| 441 |
+
|
| 442 |
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
| 443 |
+
|
| 444 |
+
## Acknowledgments
|
| 445 |
+
|
| 446 |
+
- XGBoost development team for the gradient boosting framework
|
| 447 |
+
- scikit-learn contributors for machine learning utilities
|
| 448 |
+
- Open source community for Python data science ecosystem
|
| 449 |
+
|
| 450 |
+
## Contact
|
| 451 |
+
|
| 452 |
+
For questions, issues, or suggestions, please open an issue on the repository or contact the maintainers.
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
```
|
api/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
API module for task load balancer
|
| 3 |
+
Contains inference logic and data schemas
|
| 4 |
+
"""
|
api/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (282 Bytes). View file
|
|
|
api/__pycache__/inference.cpython-313.pyc
ADDED
|
Binary file (9.85 kB). View file
|
|
|
api/__pycache__/schemas.cpython-313.pyc
ADDED
|
Binary file (4.25 kB). View file
|
|
|
api/inference.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from api.schemas import TaskAssignment, PredictionResponse
|
| 6 |
+
|
| 7 |
+
class OverloadPredictor:
|
| 8 |
+
def __init__(self):
|
| 9 |
+
self.model = joblib.load('models/xgboost_overload_classifier.pkl')
|
| 10 |
+
self.label_encoder = joblib.load('models/label_encoder.pkl')
|
| 11 |
+
self.feature_cols = [
|
| 12 |
+
'current_task_count',
|
| 13 |
+
'avg_completion_time_days',
|
| 14 |
+
'skill_match_score',
|
| 15 |
+
'total_story_points_assigned',
|
| 16 |
+
'recent_overtime_hours',
|
| 17 |
+
'task_switch_frequency',
|
| 18 |
+
'pr_review_pending',
|
| 19 |
+
'priority',
|
| 20 |
+
'estimated_story_points',
|
| 21 |
+
'days_until_deadline',
|
| 22 |
+
'required_skill_encoded',
|
| 23 |
+
'has_dependencies',
|
| 24 |
+
'task_type',
|
| 25 |
+
'team_size',
|
| 26 |
+
'sprint_days_remaining',
|
| 27 |
+
'team_avg_velocity',
|
| 28 |
+
'workload_ratio',
|
| 29 |
+
'urgency_score',
|
| 30 |
+
'capacity_indicator',
|
| 31 |
+
'overtime_risk',
|
| 32 |
+
'skill_deficit'
|
| 33 |
+
]
|
| 34 |
+
self.risk_labels = {
|
| 35 |
+
0: 'Green (Healthy)',
|
| 36 |
+
1: 'Yellow (Moderate)',
|
| 37 |
+
2: 'Red (Overload)'
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
def engineer_features(self, data: dict) -> pd.DataFrame:
|
| 41 |
+
df = pd.DataFrame([data])
|
| 42 |
+
|
| 43 |
+
df['required_skill_encoded'] = self.label_encoder.transform([df['required_skill'][0]])[0]
|
| 44 |
+
|
| 45 |
+
df['workload_ratio'] = df['total_story_points_assigned'] / 40
|
| 46 |
+
df['urgency_score'] = (31 - df['days_until_deadline']) / 30
|
| 47 |
+
df['capacity_indicator'] = (
|
| 48 |
+
df['current_task_count'] / 8 * 0.4 +
|
| 49 |
+
df['task_switch_frequency'] / 10 * 0.3 +
|
| 50 |
+
df['workload_ratio'] * 0.3
|
| 51 |
+
)
|
| 52 |
+
df['overtime_risk'] = (df['recent_overtime_hours'] / 20).clip(0, 1)
|
| 53 |
+
df['skill_deficit'] = (100 - df['skill_match_score']) / 100
|
| 54 |
+
|
| 55 |
+
return df[self.feature_cols]
|
| 56 |
+
|
| 57 |
+
def predict(self, assignment: TaskAssignment) -> PredictionResponse:
|
| 58 |
+
X = self.engineer_features(assignment.dict())
|
| 59 |
+
|
| 60 |
+
prediction = self.model.predict(X)[0]
|
| 61 |
+
probabilities = self.model.predict_proba(X)[0]
|
| 62 |
+
|
| 63 |
+
feature_values = X.iloc[0].to_dict()
|
| 64 |
+
factors = []
|
| 65 |
+
|
| 66 |
+
if feature_values['current_task_count'] > 6:
|
| 67 |
+
factors.append(f"High task count ({int(feature_values['current_task_count'])})")
|
| 68 |
+
if feature_values['workload_ratio'] > 0.75:
|
| 69 |
+
factors.append(f"High story point load ({feature_values['workload_ratio']*100:.0f}%)")
|
| 70 |
+
if assignment.skill_match_score < 60:
|
| 71 |
+
factors.append(f"Low skill match ({assignment.skill_match_score}%)")
|
| 72 |
+
if assignment.recent_overtime_hours > 10:
|
| 73 |
+
factors.append(f"Recent overtime ({assignment.recent_overtime_hours}h)")
|
| 74 |
+
if assignment.days_until_deadline < 3 and assignment.priority == 0:
|
| 75 |
+
factors.append("Urgent deadline with critical priority")
|
| 76 |
+
if feature_values['capacity_indicator'] > 0.7:
|
| 77 |
+
factors.append(f"High capacity indicator ({feature_values['capacity_indicator']:.2f})")
|
| 78 |
+
|
| 79 |
+
if prediction == 0:
|
| 80 |
+
recommendation = "Safe to assign. Developer has capacity."
|
| 81 |
+
elif prediction == 1:
|
| 82 |
+
recommendation = "Proceed with caution. Monitor workload closely."
|
| 83 |
+
else:
|
| 84 |
+
recommendation = "High overload risk. Consider reassigning or extending deadline."
|
| 85 |
+
|
| 86 |
+
return PredictionResponse(
|
| 87 |
+
developer_id=assignment.developer_id,
|
| 88 |
+
overload_risk=int(prediction),
|
| 89 |
+
risk_label=self.risk_labels[prediction],
|
| 90 |
+
confidence=float(probabilities[prediction]),
|
| 91 |
+
risk_probabilities={
|
| 92 |
+
'green': float(probabilities[0]),
|
| 93 |
+
'yellow': float(probabilities[1]),
|
| 94 |
+
'red': float(probabilities[2])
|
| 95 |
+
},
|
| 96 |
+
contributing_factors=factors if factors else ["No significant risk factors"],
|
| 97 |
+
recommendation=recommendation
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
def predict_batch(self, df: pd.DataFrame) -> pd.DataFrame:
|
| 101 |
+
df['required_skill_encoded'] = self.label_encoder.transform(df['required_skill'])
|
| 102 |
+
df['workload_ratio'] = df['total_story_points_assigned'] / 40
|
| 103 |
+
df['urgency_score'] = (31 - df['days_until_deadline']) / 30
|
| 104 |
+
df['capacity_indicator'] = (
|
| 105 |
+
df['current_task_count'] / 8 * 0.4 +
|
| 106 |
+
df['task_switch_frequency'] / 10 * 0.3 +
|
| 107 |
+
df['workload_ratio'] * 0.3
|
| 108 |
+
)
|
| 109 |
+
df['overtime_risk'] = (df['recent_overtime_hours'] / 20).clip(0, 1)
|
| 110 |
+
df['skill_deficit'] = (100 - df['skill_match_score']) / 100
|
| 111 |
+
|
| 112 |
+
X = df[self.feature_cols]
|
| 113 |
+
predictions = self.model.predict(X)
|
| 114 |
+
probabilities = self.model.predict_proba(X)
|
| 115 |
+
|
| 116 |
+
result_df = df[['developer_id']].copy()
|
| 117 |
+
result_df['predicted_risk'] = predictions
|
| 118 |
+
result_df['risk_label'] = result_df['predicted_risk'].map(self.risk_labels)
|
| 119 |
+
result_df['confidence'] = probabilities.max(axis=1)
|
| 120 |
+
result_df['green_prob'] = probabilities[:, 0]
|
| 121 |
+
result_df['yellow_prob'] = probabilities[:, 1]
|
| 122 |
+
result_df['red_prob'] = probabilities[:, 2]
|
| 123 |
+
|
| 124 |
+
return result_df
|
| 125 |
+
|
| 126 |
+
def recommend_developer(self, task_details: dict, team_workload_df: pd.DataFrame) -> pd.DataFrame:
|
| 127 |
+
"""
|
| 128 |
+
Given a new task and current team workload, recommend which developer should get it.
|
| 129 |
+
|
| 130 |
+
Args:
|
| 131 |
+
task_details: dict with priority, estimated_story_points, days_until_deadline,
|
| 132 |
+
required_skill, has_dependencies, task_type
|
| 133 |
+
team_workload_df: DataFrame with current workload for all developers
|
| 134 |
+
(developer_id, current_task_count, avg_completion_time_days,
|
| 135 |
+
skill_match_score, total_story_points_assigned,
|
| 136 |
+
recent_overtime_hours, task_switch_frequency, pr_review_pending,
|
| 137 |
+
team_size, sprint_days_remaining, team_avg_velocity)
|
| 138 |
+
|
| 139 |
+
Returns:
|
| 140 |
+
DataFrame with ranked recommendations
|
| 141 |
+
"""
|
| 142 |
+
recommendations = []
|
| 143 |
+
|
| 144 |
+
for _, dev_row in team_workload_df.iterrows():
|
| 145 |
+
assignment_data = {
|
| 146 |
+
'developer_id': int(dev_row['developer_id']),
|
| 147 |
+
'current_task_count': int(dev_row['current_task_count']),
|
| 148 |
+
'avg_completion_time_days': float(dev_row['avg_completion_time_days']),
|
| 149 |
+
'skill_match_score': int(dev_row['skill_match_score']),
|
| 150 |
+
'total_story_points_assigned': int(dev_row['total_story_points_assigned']),
|
| 151 |
+
'recent_overtime_hours': int(dev_row['recent_overtime_hours']),
|
| 152 |
+
'task_switch_frequency': float(dev_row['task_switch_frequency']),
|
| 153 |
+
'pr_review_pending': int(dev_row['pr_review_pending']),
|
| 154 |
+
'priority': int(task_details['priority']),
|
| 155 |
+
'estimated_story_points': int(task_details['estimated_story_points']),
|
| 156 |
+
'days_until_deadline': int(task_details['days_until_deadline']),
|
| 157 |
+
'required_skill': task_details['required_skill'],
|
| 158 |
+
'has_dependencies': int(task_details['has_dependencies']),
|
| 159 |
+
'task_type': int(task_details['task_type']),
|
| 160 |
+
'team_size': int(dev_row['team_size']),
|
| 161 |
+
'sprint_days_remaining': int(dev_row['sprint_days_remaining']),
|
| 162 |
+
'team_avg_velocity': int(dev_row['team_avg_velocity'])
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
assignment = TaskAssignment(**assignment_data)
|
| 166 |
+
result = self.predict(assignment)
|
| 167 |
+
|
| 168 |
+
suitability_score = (
|
| 169 |
+
result.risk_probabilities['green'] * 100 * 0.5 +
|
| 170 |
+
(assignment_data['skill_match_score'] / 100) * 40 +
|
| 171 |
+
(1 - assignment_data['current_task_count'] / 12) * 10
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
recommendations.append({
|
| 175 |
+
'developer_id': assignment_data['developer_id'],
|
| 176 |
+
'overload_risk': result.overload_risk,
|
| 177 |
+
'risk_label': result.risk_label,
|
| 178 |
+
'green_probability': result.risk_probabilities['green'],
|
| 179 |
+
'skill_match': assignment_data['skill_match_score'],
|
| 180 |
+
'current_tasks': assignment_data['current_task_count'],
|
| 181 |
+
'current_story_points': assignment_data['total_story_points_assigned'],
|
| 182 |
+
'suitability_score': round(suitability_score, 2),
|
| 183 |
+
'recommendation': result.recommendation
|
| 184 |
+
})
|
| 185 |
+
|
| 186 |
+
recommendations_df = pd.DataFrame(recommendations)
|
| 187 |
+
recommendations_df = recommendations_df.sort_values('suitability_score', ascending=False)
|
| 188 |
+
recommendations_df['rank'] = range(1, len(recommendations_df) + 1)
|
| 189 |
+
|
| 190 |
+
return recommendations_df[['rank', 'developer_id', 'risk_label', 'suitability_score',
|
| 191 |
+
'skill_match', 'current_tasks', 'current_story_points',
|
| 192 |
+
'green_probability', 'recommendation']]
|
api/schemas.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel, Field, validator
|
| 2 |
+
from typing import Dict, List
|
| 3 |
+
|
| 4 |
+
class TaskAssignment(BaseModel):
|
| 5 |
+
developer_id: int = Field(..., ge=1, description="Developer ID")
|
| 6 |
+
current_task_count: int = Field(..., ge=0, le=15)
|
| 7 |
+
avg_completion_time_days: float = Field(..., ge=1.0, le=30.0)
|
| 8 |
+
skill_match_score: int = Field(..., ge=0, le=100)
|
| 9 |
+
total_story_points_assigned: int = Field(..., ge=0, le=50)
|
| 10 |
+
recent_overtime_hours: int = Field(..., ge=0, le=25)
|
| 11 |
+
task_switch_frequency: float = Field(..., ge=0.0, le=10.0)
|
| 12 |
+
pr_review_pending: int = Field(..., ge=0, le=20)
|
| 13 |
+
priority: int = Field(..., ge=0, le=3)
|
| 14 |
+
estimated_story_points: int = Field(...)
|
| 15 |
+
days_until_deadline: int = Field(..., ge=1, le=30)
|
| 16 |
+
required_skill: str = Field(...)
|
| 17 |
+
has_dependencies: int = Field(..., ge=0, le=1)
|
| 18 |
+
task_type: int = Field(..., ge=0, le=2)
|
| 19 |
+
team_size: int = Field(..., ge=5, le=20)
|
| 20 |
+
sprint_days_remaining: int = Field(..., ge=1, le=14)
|
| 21 |
+
team_avg_velocity: int = Field(..., ge=20, le=100)
|
| 22 |
+
|
| 23 |
+
@validator('estimated_story_points')
|
| 24 |
+
def validate_fibonacci(cls, v):
|
| 25 |
+
allowed = [1, 2, 3, 5, 8, 13]
|
| 26 |
+
if v not in allowed:
|
| 27 |
+
raise ValueError(f'Story points must be one of {allowed}')
|
| 28 |
+
return v
|
| 29 |
+
|
| 30 |
+
@validator('required_skill')
|
| 31 |
+
def validate_skill(cls, v):
|
| 32 |
+
allowed = ['frontend', 'backend', 'devops', 'ml', 'testing']
|
| 33 |
+
if v not in allowed:
|
| 34 |
+
raise ValueError(f'Skill must be one of {allowed}')
|
| 35 |
+
return v
|
| 36 |
+
|
| 37 |
+
class Config:
|
| 38 |
+
schema_extra = {
|
| 39 |
+
"example": {
|
| 40 |
+
"developer_id": 5,
|
| 41 |
+
"current_task_count": 6,
|
| 42 |
+
"avg_completion_time_days": 5.5,
|
| 43 |
+
"skill_match_score": 85,
|
| 44 |
+
"total_story_points_assigned": 21,
|
| 45 |
+
"recent_overtime_hours": 8,
|
| 46 |
+
"task_switch_frequency": 4.2,
|
| 47 |
+
"pr_review_pending": 3,
|
| 48 |
+
"priority": 1,
|
| 49 |
+
"estimated_story_points": 5,
|
| 50 |
+
"days_until_deadline": 7,
|
| 51 |
+
"required_skill": "backend",
|
| 52 |
+
"has_dependencies": 0,
|
| 53 |
+
"task_type": 0,
|
| 54 |
+
"team_size": 10,
|
| 55 |
+
"sprint_days_remaining": 8,
|
| 56 |
+
"team_avg_velocity": 55
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class PredictionResponse(BaseModel):
|
| 62 |
+
developer_id: int
|
| 63 |
+
overload_risk: int
|
| 64 |
+
risk_label: str
|
| 65 |
+
confidence: float
|
| 66 |
+
risk_probabilities: Dict[str, float]
|
| 67 |
+
contributing_factors: List[str]
|
| 68 |
+
recommendation: str
|
| 69 |
+
|
| 70 |
+
class Config:
|
| 71 |
+
schema_extra = {
|
| 72 |
+
"example": {
|
| 73 |
+
"developer_id": 5,
|
| 74 |
+
"overload_risk": 1,
|
| 75 |
+
"risk_label": "Yellow (Moderate)",
|
| 76 |
+
"confidence": 0.68,
|
| 77 |
+
"risk_probabilities": {
|
| 78 |
+
"green": 0.25,
|
| 79 |
+
"yellow": 0.68,
|
| 80 |
+
"red": 0.07
|
| 81 |
+
},
|
| 82 |
+
"contributing_factors": [
|
| 83 |
+
"High task count (6)",
|
| 84 |
+
"Recent overtime (8h)"
|
| 85 |
+
],
|
| 86 |
+
"recommendation": "Proceed with caution. Monitor workload closely."
|
| 87 |
+
}
|
| 88 |
+
}
|
app.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from api.inference import OverloadPredictor
|
| 4 |
+
from api.schemas import TaskAssignment
|
| 5 |
+
|
| 6 |
+
predictor = OverloadPredictor()
|
| 7 |
+
|
| 8 |
+
def predict_single(dev_id, task_count, avg_time, skill_match, story_points_assigned,
|
| 9 |
+
overtime, task_switches, pr_pending, priority, story_points_new,
|
| 10 |
+
deadline, skill, has_deps, task_type, team_size, sprint_days, velocity):
|
| 11 |
+
try:
|
| 12 |
+
assignment = TaskAssignment(
|
| 13 |
+
developer_id=dev_id,
|
| 14 |
+
current_task_count=task_count,
|
| 15 |
+
avg_completion_time_days=avg_time,
|
| 16 |
+
skill_match_score=skill_match,
|
| 17 |
+
total_story_points_assigned=story_points_assigned,
|
| 18 |
+
recent_overtime_hours=overtime,
|
| 19 |
+
task_switch_frequency=task_switches,
|
| 20 |
+
pr_review_pending=pr_pending,
|
| 21 |
+
priority=priority,
|
| 22 |
+
estimated_story_points=story_points_new,
|
| 23 |
+
days_until_deadline=deadline,
|
| 24 |
+
required_skill=skill,
|
| 25 |
+
has_dependencies=has_deps,
|
| 26 |
+
task_type=task_type,
|
| 27 |
+
team_size=team_size,
|
| 28 |
+
sprint_days_remaining=sprint_days,
|
| 29 |
+
team_avg_velocity=velocity
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
result = predictor.predict(assignment)
|
| 33 |
+
|
| 34 |
+
output = f"""
|
| 35 |
+
### Prediction Result
|
| 36 |
+
|
| 37 |
+
**Developer ID:** {result.developer_id}
|
| 38 |
+
**Overload Risk:** {result.risk_label}
|
| 39 |
+
**Confidence:** {result.confidence:.1%}
|
| 40 |
+
|
| 41 |
+
**Risk Probabilities:**
|
| 42 |
+
- Green: {result.risk_probabilities['green']:.1%}
|
| 43 |
+
- Yellow: {result.risk_probabilities['yellow']:.1%}
|
| 44 |
+
- Red: {result.risk_probabilities['red']:.1%}
|
| 45 |
+
|
| 46 |
+
**Contributing Factors:**
|
| 47 |
+
{chr(10).join(f"- {factor}" for factor in result.contributing_factors)}
|
| 48 |
+
|
| 49 |
+
**Recommendation:**
|
| 50 |
+
{result.recommendation}
|
| 51 |
+
"""
|
| 52 |
+
return output
|
| 53 |
+
|
| 54 |
+
except Exception as e:
|
| 55 |
+
return f"Error: {str(e)}"
|
| 56 |
+
|
| 57 |
+
def predict_batch_csv(file):
|
| 58 |
+
try:
|
| 59 |
+
df = pd.read_csv(file.name)
|
| 60 |
+
results = predictor.predict_batch(df)
|
| 61 |
+
return results
|
| 62 |
+
except Exception as e:
|
| 63 |
+
return f"Error processing CSV: {str(e)}"
|
| 64 |
+
|
| 65 |
+
def recommend_assignment(priority, story_points, deadline, skill, has_deps, task_type, team_file):
|
| 66 |
+
try:
|
| 67 |
+
task_details = {
|
| 68 |
+
'priority': priority,
|
| 69 |
+
'estimated_story_points': story_points,
|
| 70 |
+
'days_until_deadline': deadline,
|
| 71 |
+
'required_skill': skill,
|
| 72 |
+
'has_dependencies': has_deps,
|
| 73 |
+
'task_type': task_type
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
team_df = pd.read_csv(team_file.name)
|
| 77 |
+
|
| 78 |
+
recommendations = predictor.recommend_developer(task_details, team_df)
|
| 79 |
+
|
| 80 |
+
summary = f"""
|
| 81 |
+
### Load Balancing Recommendation
|
| 82 |
+
|
| 83 |
+
**Task Details:**
|
| 84 |
+
- Priority: P{priority}
|
| 85 |
+
- Story Points: {story_points}
|
| 86 |
+
- Deadline: {deadline} days
|
| 87 |
+
- Required Skill: {skill}
|
| 88 |
+
|
| 89 |
+
**Top 3 Recommendations:**
|
| 90 |
+
"""
|
| 91 |
+
for idx, row in recommendations.head(3).iterrows():
|
| 92 |
+
emoji = "🥇" if row['rank'] == 1 else "🥈" if row['rank'] == 2 else "🥉"
|
| 93 |
+
summary += f"\n{emoji} **Developer {row['developer_id']}** - {row['risk_label']}"
|
| 94 |
+
summary += f"\n - Suitability Score: {row['suitability_score']}/100"
|
| 95 |
+
summary += f"\n - Skill Match: {row['skill_match']}%"
|
| 96 |
+
summary += f"\n - Current Load: {row['current_tasks']} tasks, {row['current_story_points']} points"
|
| 97 |
+
summary += f"\n - {row['recommendation']}\n"
|
| 98 |
+
|
| 99 |
+
return summary, recommendations
|
| 100 |
+
|
| 101 |
+
except Exception as e:
|
| 102 |
+
return f"Error: {str(e)}", None
|
| 103 |
+
|
| 104 |
+
with gr.Blocks(title="Task Load Balancer", theme=gr.themes.Soft()) as demo:
|
| 105 |
+
gr.Markdown("""
|
| 106 |
+
# Intelligent Task Load Balancer
|
| 107 |
+
|
| 108 |
+
**Predict developer overload risk using ML before assigning tasks.**
|
| 109 |
+
|
| 110 |
+
This system analyzes workload, skills, deadlines, and team context to recommend optimal task assignments.
|
| 111 |
+
|
| 112 |
+
### How to Use:
|
| 113 |
+
1. **Single Prediction:** Check risk for specific developer
|
| 114 |
+
2. **Batch Prediction:** Upload CSV with multiple assignments
|
| 115 |
+
3. **Load Balancing:** Get recommendation for which developer should get a new task
|
| 116 |
+
""")
|
| 117 |
+
|
| 118 |
+
with gr.Tab("Single Prediction"):
|
| 119 |
+
gr.Markdown("### Developer & Task Details")
|
| 120 |
+
|
| 121 |
+
with gr.Row():
|
| 122 |
+
with gr.Column():
|
| 123 |
+
dev_id = gr.Number(label="Developer ID", value=5)
|
| 124 |
+
task_count = gr.Slider(0, 12, value=4, step=1, label="Current Task Count")
|
| 125 |
+
avg_time = gr.Slider(1, 25, value=6, step=0.5, label="Avg Completion Time (days)")
|
| 126 |
+
skill_match = gr.Slider(0, 100, value=85, step=5, label="Skill Match Score (%)")
|
| 127 |
+
story_assigned = gr.Slider(0, 40, value=15, step=1, label="Current Story Points")
|
| 128 |
+
overtime = gr.Slider(0, 20, value=2, step=1, label="Recent Overtime (hours)")
|
| 129 |
+
|
| 130 |
+
with gr.Column():
|
| 131 |
+
task_switches = gr.Slider(0, 10, value=3, step=0.5, label="Task Switches/Day")
|
| 132 |
+
pr_pending = gr.Slider(0, 15, value=2, step=1, label="PRs Pending Review")
|
| 133 |
+
priority = gr.Radio([0, 1, 2, 3], value=1, label="Priority (0=P0, 3=P3)")
|
| 134 |
+
story_new = gr.Radio([1, 2, 3, 5, 8, 13], value=5, label="New Task Story Points")
|
| 135 |
+
deadline = gr.Slider(1, 30, value=7, step=1, label="Days Until Deadline")
|
| 136 |
+
skill = gr.Dropdown(["frontend", "backend", "devops", "ml", "testing"],
|
| 137 |
+
value="backend", label="Required Skill")
|
| 138 |
+
|
| 139 |
+
with gr.Row():
|
| 140 |
+
has_deps = gr.Radio([0, 1], value=0, label="Has Dependencies?")
|
| 141 |
+
task_type = gr.Radio([0, 1, 2], value=0, label="Task Type (0=feature, 1=bug, 2=maint)")
|
| 142 |
+
team_size = gr.Slider(5, 15, value=10, step=1, label="Team Size")
|
| 143 |
+
sprint_days = gr.Slider(1, 14, value=8, step=1, label="Sprint Days Remaining")
|
| 144 |
+
velocity = gr.Slider(20, 80, value=50, step=5, label="Team Avg Velocity")
|
| 145 |
+
|
| 146 |
+
predict_btn = gr.Button("Predict Overload Risk", variant="primary")
|
| 147 |
+
output_single = gr.Markdown()
|
| 148 |
+
|
| 149 |
+
predict_btn.click(
|
| 150 |
+
predict_single,
|
| 151 |
+
inputs=[dev_id, task_count, avg_time, skill_match, story_assigned,
|
| 152 |
+
overtime, task_switches, pr_pending, priority, story_new,
|
| 153 |
+
deadline, skill, has_deps, task_type, team_size, sprint_days, velocity],
|
| 154 |
+
outputs=output_single
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
with gr.Tab("Batch Prediction (CSV Upload)"):
|
| 158 |
+
gr.Markdown("""
|
| 159 |
+
### Upload CSV File
|
| 160 |
+
|
| 161 |
+
**Required columns:**
|
| 162 |
+
`developer_id`, `current_task_count`, `avg_completion_time_days`, `skill_match_score`,
|
| 163 |
+
`total_story_points_assigned`, `recent_overtime_hours`, `task_switch_frequency`,
|
| 164 |
+
`pr_review_pending`, `priority`, `estimated_story_points`, `days_until_deadline`,
|
| 165 |
+
`required_skill`, `has_dependencies`, `task_type`, `team_size`, `sprint_days_remaining`,
|
| 166 |
+
`team_avg_velocity`
|
| 167 |
+
""")
|
| 168 |
+
|
| 169 |
+
file_input = gr.File(label="Upload CSV", file_types=[".csv"])
|
| 170 |
+
predict_csv_btn = gr.Button("Predict Batch", variant="primary")
|
| 171 |
+
output_batch = gr.Dataframe()
|
| 172 |
+
|
| 173 |
+
predict_csv_btn.click(predict_batch_csv, inputs=file_input, outputs=output_batch)
|
| 174 |
+
|
| 175 |
+
with gr.Tab("Load Balancing (Recommend Developer)"):
|
| 176 |
+
gr.Markdown("""
|
| 177 |
+
### Find Best Developer for New Task
|
| 178 |
+
|
| 179 |
+
Upload team workload CSV and specify task details to get ranked recommendations.
|
| 180 |
+
""")
|
| 181 |
+
|
| 182 |
+
with gr.Row():
|
| 183 |
+
with gr.Column():
|
| 184 |
+
gr.Markdown("**Task Details:**")
|
| 185 |
+
task_priority = gr.Radio([0, 1, 2, 3], value=1, label="Priority (0=P0, 3=P3)")
|
| 186 |
+
task_story_points = gr.Radio([1, 2, 3, 5, 8, 13], value=5, label="Story Points")
|
| 187 |
+
task_deadline = gr.Slider(1, 30, value=7, step=1, label="Days Until Deadline")
|
| 188 |
+
task_skill = gr.Dropdown(["frontend", "backend", "devops", "ml", "testing"],
|
| 189 |
+
value="backend", label="Required Skill")
|
| 190 |
+
task_has_deps = gr.Radio([0, 1], value=0, label="Has Dependencies?")
|
| 191 |
+
task_task_type = gr.Radio([0, 1, 2], value=0, label="Task Type")
|
| 192 |
+
|
| 193 |
+
with gr.Column():
|
| 194 |
+
gr.Markdown("**Team Workload CSV:**")
|
| 195 |
+
gr.Markdown("Upload CSV with columns: `developer_id`, `current_task_count`, `avg_completion_time_days`, `skill_match_score`, `total_story_points_assigned`, `recent_overtime_hours`, `task_switch_frequency`, `pr_review_pending`, `team_size`, `sprint_days_remaining`, `team_avg_velocity`")
|
| 196 |
+
team_workload_file = gr.File(label="Upload Team Workload CSV", file_types=[".csv"])
|
| 197 |
+
|
| 198 |
+
recommend_btn = gr.Button("Get Recommendation", variant="primary")
|
| 199 |
+
recommendation_summary = gr.Markdown()
|
| 200 |
+
recommendation_table = gr.Dataframe()
|
| 201 |
+
|
| 202 |
+
recommend_btn.click(
|
| 203 |
+
recommend_assignment,
|
| 204 |
+
inputs=[task_priority, task_story_points, task_deadline, task_skill,
|
| 205 |
+
task_has_deps, task_task_type, team_workload_file],
|
| 206 |
+
outputs=[recommendation_summary, recommendation_table]
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
if __name__ == "__main__":
|
| 210 |
+
demo.launch()
|
data/sample_input.csv
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
assignment_id,developer_id,task_id,current_task_count,avg_completion_time_days,skill_match_score,total_story_points_assigned,recent_overtime_hours,task_switch_frequency,pr_review_pending,priority,estimated_story_points,days_until_deadline,required_skill,has_dependencies,task_type,team_size,sprint_days_remaining,team_avg_velocity,overload_risk,actual_completion_days
|
| 2 |
+
1,8,1,4,5.3,81,8,3,4.12,0,3,5,1,frontend,0,0,8,1,61,0,5.8
|
| 3 |
+
2,6,2,6,7.71,73,18,6,2.91,2,1,5,2,frontend,1,1,9,4,63,1,9.5
|
| 4 |
+
3,3,3,8,10.07,44,16,0,7.95,2,3,3,4,devops,0,1,11,7,43,2,13.4
|
| 5 |
+
4,3,4,5,14.8,71,20,5,3.68,4,1,3,23,testing,0,0,12,11,63,1,9.9
|
| 6 |
+
5,9,5,2,5.31,57,6,8,1.31,1,3,2,28,ml,0,0,10,9,67,0,1.6
|
| 7 |
+
6,10,6,3,5.52,63,9,4,2.28,2,3,2,1,frontend,0,1,9,6,66,0,2.5
|
| 8 |
+
7,4,7,5,7.18,70,20,0,2.12,2,2,2,23,frontend,0,1,8,11,62,0,3.9
|
| 9 |
+
8,5,8,5,3.47,85,10,9,3.9,6,0,5,23,devops,1,1,12,2,52,0,2.3
|
| 10 |
+
9,12,9,6,7.41,97,24,1,2.8,5,2,3,8,ml,0,1,8,1,62,0,3.4
|
| 11 |
+
10,12,10,0,9.57,54,0,3,1.93,2,1,3,21,frontend,0,1,9,6,57,0,5.8
|
| 12 |
+
11,9,11,4,6.52,69,12,8,4.74,7,1,3,25,devops,1,2,9,10,56,0,1.1
|
| 13 |
+
12,8,12,5,6.5,90,10,13,4.14,0,1,5,29,testing,1,0,11,5,35,0,5.0
|
| 14 |
+
13,4,13,7,4.78,85,14,0,5.37,1,1,8,2,backend,0,0,12,7,44,0,8.8
|
| 15 |
+
14,8,14,1,6.21,77,2,8,2.09,3,3,5,4,frontend,0,0,12,12,65,0,6.0
|
| 16 |
+
15,4,15,4,5.48,87,12,4,3.89,4,2,5,19,ml,1,1,12,12,47,0,5.8
|
| 17 |
+
16,4,16,5,7.53,76,10,1,4.85,4,1,5,26,frontend,1,0,9,5,69,0,8.7
|
| 18 |
+
17,1,17,3,12.91,43,9,2,2.73,2,2,5,20,frontend,0,1,10,13,61,0,15.0
|
| 19 |
+
18,8,18,0,5.34,81,0,5,2.42,4,2,1,24,backend,0,1,12,6,55,0,1.2
|
| 20 |
+
19,4,19,4,6.69,73,16,1,4.85,4,2,2,8,frontend,0,1,8,9,67,0,1.0
|
| 21 |
+
20,8,20,8,3.13,86,16,6,5.92,6,0,5,3,ml,0,1,10,5,57,0,3.6
|
| 22 |
+
21,4,21,6,6.36,90,18,2,4.49,3,2,3,26,testing,0,2,11,2,68,0,6.3
|
| 23 |
+
22,2,22,7,14.49,62,20,5,4.26,0,2,2,3,devops,1,0,11,8,38,2,8.3
|
| 24 |
+
23,8,23,5,3.16,85,15,0,3.38,2,2,1,28,devops,1,0,8,8,69,0,1.0
|
| 25 |
+
24,5,24,3,3.74,79,12,4,2.74,2,2,3,1,testing,0,2,9,14,59,0,3.6
|
| 26 |
+
25,6,25,7,4.69,92,21,3,4.98,3,1,3,14,frontend,1,0,12,4,58,0,1.0
|
| 27 |
+
26,12,26,0,9.85,99,0,0,2.17,5,1,5,20,ml,0,1,12,14,45,0,9.1
|
| 28 |
+
27,5,27,5,3.69,77,10,5,3.79,6,2,5,3,frontend,0,0,12,8,45,0,4.6
|
| 29 |
+
28,1,28,4,12.12,53,12,6,3.32,3,2,2,26,backend,1,0,10,6,40,1,6.2
|
| 30 |
+
29,7,29,6,4.24,77,24,0,2.61,3,2,2,23,testing,1,0,11,13,36,0,1.5
|
| 31 |
+
30,5,30,2,7.54,81,6,1,1.56,3,1,3,14,ml,0,1,12,8,62,0,4.3
|
| 32 |
+
31,2,31,6,14.45,50,20,1,2.68,3,2,3,1,backend,0,0,10,2,61,1,13.1
|
| 33 |
+
32,6,32,3,4.56,91,6,3,2.08,0,2,1,20,ml,0,1,8,7,35,0,1.0
|
| 34 |
+
33,6,33,6,6.57,88,18,2,3.32,2,1,8,13,backend,0,0,11,2,41,0,9.0
|
| 35 |
+
34,6,34,7,7.94,88,21,7,5.59,2,3,1,3,testing,1,2,12,12,52,0,1.0
|
| 36 |
+
35,7,35,5,7.87,91,10,8,3.46,3,1,5,10,frontend,0,0,9,10,63,0,5.5
|
| 37 |
+
36,2,36,3,10.84,51,9,7,1.02,0,1,8,11,backend,0,0,9,13,51,0,20.6
|
| 38 |
+
37,5,37,2,6.02,89,6,0,2.59,7,2,2,22,devops,1,0,12,11,68,0,5.5
|
| 39 |
+
38,4,38,4,3.39,84,16,1,3.77,1,3,1,26,frontend,1,2,10,8,65,0,2.3
|
| 40 |
+
39,4,39,4,3.22,87,16,20,3.67,2,2,1,3,testing,0,0,10,2,51,0,2.7
|
| 41 |
+
40,8,40,2,6.62,82,8,1,1.85,5,0,13,3,testing,0,2,10,7,63,0,19.3
|
| 42 |
+
41,4,41,3,4.68,81,6,5,0.51,5,3,1,1,ml,0,1,12,11,40,0,1.2
|
| 43 |
+
42,11,42,6,5.06,62,18,0,4.87,4,2,3,3,backend,0,0,10,6,47,0,1.0
|
| 44 |
+
43,8,43,3,7.44,85,6,7,0.59,4,0,8,2,testing,0,0,8,2,66,0,12.0
|
| 45 |
+
44,5,44,6,3.8,90,12,7,4.09,4,3,1,13,devops,0,0,11,2,48,0,1.9
|
| 46 |
+
45,1,45,7,13.33,61,20,2,7.36,3,1,5,20,ml,0,0,9,8,52,2,19.2
|
| 47 |
+
46,3,46,4,9.11,66,12,20,3.28,3,1,3,25,devops,0,2,11,13,55,2,7.4
|
| 48 |
+
47,5,47,1,6.26,83,3,7,1.68,7,1,3,6,ml,0,0,8,14,54,0,3.3
|
| 49 |
+
48,8,48,4,3.36,89,12,2,3.8,4,2,1,1,ml,0,1,9,12,67,0,1.0
|
| 50 |
+
49,4,49,5,7.11,77,15,0,2.31,2,3,1,21,ml,0,1,11,14,41,0,4.4
|
| 51 |
+
50,5,50,2,5.19,92,6,0,1.12,2,3,2,3,testing,1,0,9,3,56,0,1.0
|
data/task_assignments.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
models/label_encoder.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:139d59c04f323beb2a0f530fa7e88efc4c657281b136036ebdde4d103dad4ddb
|
| 3 |
+
size 518
|
models/model_metadata.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "XGBoost Classifier",
|
| 3 |
+
"n_estimators": 200,
|
| 4 |
+
"max_depth": 6,
|
| 5 |
+
"learning_rate": 0.1,
|
| 6 |
+
"n_features": 21,
|
| 7 |
+
"n_classes": 3,
|
| 8 |
+
"accuracy": 0.889,
|
| 9 |
+
"f1_score": 0.8828844998124402,
|
| 10 |
+
"cv_mean": 0.9034527245420856,
|
| 11 |
+
"cv_std": 0.004854076089972276,
|
| 12 |
+
"train_samples": 4000,
|
| 13 |
+
"test_samples": 1000,
|
| 14 |
+
"feature_names": [
|
| 15 |
+
"current_task_count",
|
| 16 |
+
"avg_completion_time_days",
|
| 17 |
+
"skill_match_score",
|
| 18 |
+
"total_story_points_assigned",
|
| 19 |
+
"recent_overtime_hours",
|
| 20 |
+
"task_switch_frequency",
|
| 21 |
+
"pr_review_pending",
|
| 22 |
+
"priority",
|
| 23 |
+
"estimated_story_points",
|
| 24 |
+
"days_until_deadline",
|
| 25 |
+
"required_skill_encoded",
|
| 26 |
+
"has_dependencies",
|
| 27 |
+
"task_type",
|
| 28 |
+
"team_size",
|
| 29 |
+
"sprint_days_remaining",
|
| 30 |
+
"team_avg_velocity",
|
| 31 |
+
"workload_ratio",
|
| 32 |
+
"urgency_score",
|
| 33 |
+
"capacity_indicator",
|
| 34 |
+
"overtime_risk",
|
| 35 |
+
"skill_deficit"
|
| 36 |
+
],
|
| 37 |
+
"class_names": [
|
| 38 |
+
"Green",
|
| 39 |
+
"Yellow",
|
| 40 |
+
"Red"
|
| 41 |
+
]
|
| 42 |
+
}
|
models/xgboost_overload_classifier.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:973e3c9fe6bdcc207e8c56d99723e594bca7d471efd75f87e74bed8d98a9064b
|
| 3 |
+
size 1683133
|
requirements.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
gradio
|
| 4 |
+
pydantic
|
| 5 |
+
scikit-learn
|
| 6 |
+
pandas
|
| 7 |
+
numpy
|
| 8 |
+
joblib
|
| 9 |
+
matplotlib
|
| 10 |
+
seaborn
|
| 11 |
+
xgboost
|
| 12 |
+
shap
|
results/confusion_matrix.png
ADDED
|
results/feature_importance.csv
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
feature,importance
|
| 2 |
+
capacity_indicator,0.13117875
|
| 3 |
+
current_task_count,0.112985805
|
| 4 |
+
workload_ratio,0.11082915
|
| 5 |
+
total_story_points_assigned,0.091274925
|
| 6 |
+
avg_completion_time_days,0.07084232
|
| 7 |
+
skill_deficit,0.05964846
|
| 8 |
+
skill_match_score,0.05655115
|
| 9 |
+
estimated_story_points,0.0399822
|
| 10 |
+
has_dependencies,0.03781044
|
| 11 |
+
priority,0.0366023
|
| 12 |
+
overtime_risk,0.03374501
|
| 13 |
+
recent_overtime_hours,0.032092527
|
| 14 |
+
urgency_score,0.026155934
|
| 15 |
+
task_switch_frequency,0.024822243
|
| 16 |
+
days_until_deadline,0.02316302
|
| 17 |
+
pr_review_pending,0.01957131
|
| 18 |
+
sprint_days_remaining,0.019375606
|
| 19 |
+
team_size,0.019251108
|
| 20 |
+
team_avg_velocity,0.018156795
|
| 21 |
+
task_type,0.01798987
|
| 22 |
+
required_skill_encoded,0.017970989
|
results/feature_importance.png
ADDED
|
scripts/generate_data.py
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
np.random.seed(42)
|
| 6 |
+
|
| 7 |
+
print("=" * 60)
|
| 8 |
+
print("GENERATING SYNTHETIC TASK ASSIGNMENT DATASET")
|
| 9 |
+
print("=" * 60)
|
| 10 |
+
|
| 11 |
+
n_samples = 5000
|
| 12 |
+
n_developers = 12
|
| 13 |
+
|
| 14 |
+
dev_profiles = {
|
| 15 |
+
'junior': {
|
| 16 |
+
'ids': [1, 2, 3],
|
| 17 |
+
'avg_time': (8, 15),
|
| 18 |
+
'skill_range': (40, 75),
|
| 19 |
+
'max_capacity': 20,
|
| 20 |
+
'overtime_tolerance': 8
|
| 21 |
+
},
|
| 22 |
+
'senior': {
|
| 23 |
+
'ids': [4, 5, 6, 7, 8],
|
| 24 |
+
'avg_time': (3, 8),
|
| 25 |
+
'skill_range': (70, 95),
|
| 26 |
+
'max_capacity': 35,
|
| 27 |
+
'overtime_tolerance': 15
|
| 28 |
+
},
|
| 29 |
+
'specialist': {
|
| 30 |
+
'ids': [9, 10, 11, 12],
|
| 31 |
+
'avg_time': (4, 10),
|
| 32 |
+
'skill_range': (60, 100),
|
| 33 |
+
'max_capacity': 28,
|
| 34 |
+
'overtime_tolerance': 12
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
specialist_skills = {
|
| 39 |
+
9: 'frontend',
|
| 40 |
+
10: 'backend',
|
| 41 |
+
11: 'devops',
|
| 42 |
+
12: 'ml'
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
data = []
|
| 46 |
+
|
| 47 |
+
for i in range(1, n_samples + 1):
|
| 48 |
+
dev_type = np.random.choice(['junior', 'senior', 'specialist'], p=[0.2, 0.5, 0.3])
|
| 49 |
+
profile = dev_profiles[dev_type]
|
| 50 |
+
dev_id = np.random.choice(profile['ids'])
|
| 51 |
+
|
| 52 |
+
current_tasks = max(0, int(np.random.poisson(4)))
|
| 53 |
+
current_tasks = min(current_tasks, 12)
|
| 54 |
+
|
| 55 |
+
avg_comp_time = np.random.uniform(*profile['avg_time'])
|
| 56 |
+
|
| 57 |
+
story_points_assigned = current_tasks * np.random.randint(2, 5)
|
| 58 |
+
story_points_assigned = min(story_points_assigned, profile['max_capacity'])
|
| 59 |
+
|
| 60 |
+
overtime = max(0, int(np.random.exponential(4)))
|
| 61 |
+
overtime = min(overtime, 20)
|
| 62 |
+
|
| 63 |
+
if current_tasks > 6:
|
| 64 |
+
task_switches = np.random.uniform(4, 8)
|
| 65 |
+
elif current_tasks > 3:
|
| 66 |
+
task_switches = np.random.uniform(2, 5)
|
| 67 |
+
else:
|
| 68 |
+
task_switches = np.random.uniform(0.5, 3)
|
| 69 |
+
task_switches = round(task_switches, 2)
|
| 70 |
+
|
| 71 |
+
pr_pending = max(0, int(np.random.poisson(3)))
|
| 72 |
+
pr_pending = min(pr_pending, 15)
|
| 73 |
+
|
| 74 |
+
priority = np.random.choice([0, 1, 2, 3], p=[0.1, 0.3, 0.4, 0.2])
|
| 75 |
+
|
| 76 |
+
if priority == 0:
|
| 77 |
+
story_points = np.random.choice([5, 8, 13], p=[0.5, 0.3, 0.2])
|
| 78 |
+
elif priority == 1:
|
| 79 |
+
story_points = np.random.choice([3, 5, 8], p=[0.4, 0.4, 0.2])
|
| 80 |
+
else:
|
| 81 |
+
story_points = np.random.choice([1, 2, 3, 5], p=[0.2, 0.3, 0.3, 0.2])
|
| 82 |
+
|
| 83 |
+
is_sprint_end = np.random.random() < 0.35
|
| 84 |
+
if is_sprint_end:
|
| 85 |
+
days_deadline = np.random.randint(1, 4)
|
| 86 |
+
else:
|
| 87 |
+
days_deadline = np.random.randint(4, 31)
|
| 88 |
+
|
| 89 |
+
required_skill = np.random.choice(['frontend', 'backend', 'devops', 'ml', 'testing'])
|
| 90 |
+
|
| 91 |
+
if dev_id in specialist_skills:
|
| 92 |
+
if required_skill == specialist_skills[dev_id]:
|
| 93 |
+
skill_match = np.random.randint(85, 101)
|
| 94 |
+
else:
|
| 95 |
+
skill_match = np.random.randint(45, 75)
|
| 96 |
+
else:
|
| 97 |
+
base_skill = profile['skill_range']
|
| 98 |
+
skill_match = np.random.randint(*base_skill)
|
| 99 |
+
|
| 100 |
+
skill_match = np.clip(skill_match, 0, 100)
|
| 101 |
+
|
| 102 |
+
has_deps = 1 if np.random.random() < 0.3 else 0
|
| 103 |
+
|
| 104 |
+
task_type = np.random.choice([0, 1, 2], p=[0.5, 0.3, 0.2])
|
| 105 |
+
|
| 106 |
+
team_size = np.random.randint(8, 13)
|
| 107 |
+
sprint_days = np.random.randint(1, 15)
|
| 108 |
+
team_velocity = np.random.randint(35, 71)
|
| 109 |
+
|
| 110 |
+
workload_ratio = (story_points_assigned + story_points) / profile['max_capacity']
|
| 111 |
+
task_count_ratio = current_tasks / 8
|
| 112 |
+
switch_ratio = min(task_switches, 10) / 10
|
| 113 |
+
skill_penalty = (100 - skill_match) / 100
|
| 114 |
+
|
| 115 |
+
capacity = (
|
| 116 |
+
workload_ratio * 0.35 +
|
| 117 |
+
task_count_ratio * 0.25 +
|
| 118 |
+
switch_ratio * 0.20 +
|
| 119 |
+
skill_penalty * 0.15 +
|
| 120 |
+
(pr_pending / 15) * 0.05
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
if overtime > profile['overtime_tolerance']:
|
| 124 |
+
fatigue_multiplier = 1 + ((overtime - profile['overtime_tolerance']) / 10)
|
| 125 |
+
capacity *= fatigue_multiplier
|
| 126 |
+
|
| 127 |
+
if days_deadline <= 2 and priority == 0:
|
| 128 |
+
capacity *= 1.25
|
| 129 |
+
elif days_deadline <= 3 and priority <= 1:
|
| 130 |
+
capacity *= 1.15
|
| 131 |
+
|
| 132 |
+
if has_deps == 1 and current_tasks > 5:
|
| 133 |
+
capacity *= 1.12
|
| 134 |
+
|
| 135 |
+
if skill_match < 50 and workload_ratio > 0.7:
|
| 136 |
+
capacity *= 1.20
|
| 137 |
+
|
| 138 |
+
if current_tasks > 8 and task_switches > 6:
|
| 139 |
+
capacity *= 1.18
|
| 140 |
+
|
| 141 |
+
noise = np.random.normal(0, 0.05)
|
| 142 |
+
capacity += noise
|
| 143 |
+
|
| 144 |
+
green_threshold = 0.65
|
| 145 |
+
yellow_threshold = 0.82
|
| 146 |
+
|
| 147 |
+
if dev_type == 'junior':
|
| 148 |
+
green_threshold = 0.55
|
| 149 |
+
yellow_threshold = 0.72
|
| 150 |
+
elif dev_type == 'senior':
|
| 151 |
+
green_threshold = 0.70
|
| 152 |
+
yellow_threshold = 0.87
|
| 153 |
+
|
| 154 |
+
if capacity < green_threshold:
|
| 155 |
+
risk = 0
|
| 156 |
+
elif capacity < yellow_threshold:
|
| 157 |
+
risk = 1
|
| 158 |
+
else:
|
| 159 |
+
risk = 2
|
| 160 |
+
|
| 161 |
+
base_completion = avg_comp_time * (story_points / 5)
|
| 162 |
+
|
| 163 |
+
if skill_match < 60:
|
| 164 |
+
base_completion *= 1.3
|
| 165 |
+
elif skill_match > 85:
|
| 166 |
+
base_completion *= 0.85
|
| 167 |
+
|
| 168 |
+
if risk == 0:
|
| 169 |
+
completion_multiplier = 1.0
|
| 170 |
+
elif risk == 1:
|
| 171 |
+
completion_multiplier = 1.2
|
| 172 |
+
else:
|
| 173 |
+
completion_multiplier = 1.5
|
| 174 |
+
|
| 175 |
+
actual_days = base_completion * completion_multiplier
|
| 176 |
+
actual_days += np.random.normal(0, 1.5)
|
| 177 |
+
actual_days = max(1, round(actual_days, 1))
|
| 178 |
+
|
| 179 |
+
data.append([
|
| 180 |
+
i, dev_id, i, current_tasks, round(avg_comp_time, 2),
|
| 181 |
+
skill_match, story_points_assigned, overtime,
|
| 182 |
+
task_switches, pr_pending, priority, story_points,
|
| 183 |
+
days_deadline, required_skill, has_deps, task_type,
|
| 184 |
+
team_size, sprint_days, team_velocity, risk,
|
| 185 |
+
actual_days
|
| 186 |
+
])
|
| 187 |
+
|
| 188 |
+
df = pd.DataFrame(data, columns=[
|
| 189 |
+
'assignment_id', 'developer_id', 'task_id', 'current_task_count',
|
| 190 |
+
'avg_completion_time_days', 'skill_match_score', 'total_story_points_assigned',
|
| 191 |
+
'recent_overtime_hours', 'task_switch_frequency', 'pr_review_pending',
|
| 192 |
+
'priority', 'estimated_story_points', 'days_until_deadline',
|
| 193 |
+
'required_skill', 'has_dependencies', 'task_type', 'team_size',
|
| 194 |
+
'sprint_days_remaining', 'team_avg_velocity', 'overload_risk',
|
| 195 |
+
'actual_completion_days'
|
| 196 |
+
])
|
| 197 |
+
|
| 198 |
+
print("\n QUALITY CHECKS")
|
| 199 |
+
print("-" * 60)
|
| 200 |
+
|
| 201 |
+
print("\n1. Missing Values:")
|
| 202 |
+
missing = df.isnull().sum().sum()
|
| 203 |
+
print(f" Total missing: {missing} {' PASS' if missing == 0 else '❌ FAIL'}")
|
| 204 |
+
|
| 205 |
+
print("\n2. Value Range Validation:")
|
| 206 |
+
checks = [
|
| 207 |
+
('skill_match_score', 0, 100),
|
| 208 |
+
('current_task_count', 0, 15),
|
| 209 |
+
('recent_overtime_hours', 0, 25),
|
| 210 |
+
('task_switch_frequency', 0, 10),
|
| 211 |
+
('priority', 0, 3),
|
| 212 |
+
('overload_risk', 0, 2),
|
| 213 |
+
]
|
| 214 |
+
|
| 215 |
+
all_valid = True
|
| 216 |
+
for col, min_val, max_val in checks:
|
| 217 |
+
valid = df[col].between(min_val, max_val).all()
|
| 218 |
+
actual_min = df[col].min()
|
| 219 |
+
actual_max = df[col].max()
|
| 220 |
+
status = 'Ok' if valid else 'Not OK'
|
| 221 |
+
print(f" {col}: [{actual_min}, {actual_max}] {status}")
|
| 222 |
+
all_valid = all_valid and valid
|
| 223 |
+
|
| 224 |
+
print(f"\n Overall: {'PASS' if all_valid else 'FAIL'}")
|
| 225 |
+
|
| 226 |
+
print("\n3. Class Distribution:")
|
| 227 |
+
class_dist = df['overload_risk'].value_counts().sort_index()
|
| 228 |
+
class_pct = df['overload_risk'].value_counts(normalize=True).sort_index()
|
| 229 |
+
for cls in [0, 1, 2]:
|
| 230 |
+
count = class_dist.get(cls, 0)
|
| 231 |
+
pct = class_pct.get(cls, 0) * 100
|
| 232 |
+
print(f" Class {cls}: {count:4d} samples ({pct:5.2f}%)")
|
| 233 |
+
|
| 234 |
+
min_class_size = class_dist.min()
|
| 235 |
+
print(f" Minimum class size: {min_class_size} {'PASS' if min_class_size >= 100 else 'WARNING'}")
|
| 236 |
+
|
| 237 |
+
print("\n4. Feature Correlations with Target:")
|
| 238 |
+
correlations = df.select_dtypes(include=[np.number]).corr()['overload_risk'].sort_values(ascending=False)
|
| 239 |
+
print("\n Top Positive Correlations:")
|
| 240 |
+
for feat, corr in correlations.head(6).items():
|
| 241 |
+
if feat != 'overload_risk':
|
| 242 |
+
print(f" {feat:35s}: {corr:+.3f}")
|
| 243 |
+
|
| 244 |
+
print("\n Top Negative Correlations:")
|
| 245 |
+
for feat, corr in correlations.tail(5).items():
|
| 246 |
+
if feat != 'overload_risk':
|
| 247 |
+
print(f" {feat:35s}: {corr:+.3f}")
|
| 248 |
+
|
| 249 |
+
print("\n5. Statistical Summary:")
|
| 250 |
+
print(f" Total samples: {len(df)}")
|
| 251 |
+
print(f" Total features: {len(df.columns) - 1}")
|
| 252 |
+
print(f" Developers: {df['developer_id'].nunique()}")
|
| 253 |
+
print(f" Avg tasks per developer: {df['current_task_count'].mean():.2f}")
|
| 254 |
+
print(f" Avg story points: {df['total_story_points_assigned'].mean():.2f}")
|
| 255 |
+
print(f" Avg skill match: {df['skill_match_score'].mean():.1f}%")
|
| 256 |
+
|
| 257 |
+
print("\n6. Logical Consistency:")
|
| 258 |
+
consistency_checks = []
|
| 259 |
+
consistency_checks.append(df['estimated_story_points'].isin([1,2,3,5,8,13]).all())
|
| 260 |
+
consistency_checks.append(df['required_skill'].isin(['frontend','backend','devops','ml','testing']).all())
|
| 261 |
+
consistency_checks.append((df['has_dependencies'].isin([0, 1])).all())
|
| 262 |
+
consistency_checks.append((df['task_type'].isin([0, 1, 2])).all())
|
| 263 |
+
|
| 264 |
+
if all(consistency_checks):
|
| 265 |
+
print("All consistency checks passed")
|
| 266 |
+
else:
|
| 267 |
+
print("Some consistency checks failed")
|
| 268 |
+
|
| 269 |
+
Path('data').mkdir(exist_ok=True)
|
| 270 |
+
df.to_csv('data/task_assignments.csv', index=False)
|
| 271 |
+
|
| 272 |
+
sample_df = df.head(50)
|
| 273 |
+
sample_df.to_csv('data/sample_input.csv', index=False)
|
| 274 |
+
|
| 275 |
+
print("\n" + "=" * 60)
|
| 276 |
+
print("💾 FILES SAVED")
|
| 277 |
+
print("=" * 60)
|
| 278 |
+
print(f"data/task_assignments.csv ({len(df)} rows)")
|
| 279 |
+
print(f"data/sample_input.csv (50 rows for testing)")
|
| 280 |
+
print("\nDataset generation complete!")
|
scripts/train_model.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
import joblib
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from sklearn.model_selection import train_test_split, cross_val_score, StratifiedKFold
|
| 6 |
+
from sklearn.preprocessing import LabelEncoder
|
| 7 |
+
from sklearn.metrics import classification_report, confusion_matrix, f1_score, accuracy_score
|
| 8 |
+
import xgboost as xgb
|
| 9 |
+
import matplotlib.pyplot as plt
|
| 10 |
+
import seaborn as sns
|
| 11 |
+
import json
|
| 12 |
+
|
| 13 |
+
df = pd.read_csv('data/task_assignments.csv')
|
| 14 |
+
|
| 15 |
+
df['workload_ratio'] = df['total_story_points_assigned'] / 40
|
| 16 |
+
df['urgency_score'] = (31 - df['days_until_deadline']) / 30
|
| 17 |
+
df['capacity_indicator'] = (
|
| 18 |
+
df['current_task_count'] / 8 * 0.4 +
|
| 19 |
+
df['task_switch_frequency'] / 10 * 0.3 +
|
| 20 |
+
df['workload_ratio'] * 0.3
|
| 21 |
+
)
|
| 22 |
+
df['overtime_risk'] = (df['recent_overtime_hours'] / 20).clip(0, 1)
|
| 23 |
+
df['skill_deficit'] = (100 - df['skill_match_score']) / 100
|
| 24 |
+
|
| 25 |
+
le = LabelEncoder()
|
| 26 |
+
df['required_skill_encoded'] = le.fit_transform(df['required_skill'])
|
| 27 |
+
|
| 28 |
+
Path('models').mkdir(exist_ok=True)
|
| 29 |
+
joblib.dump(le, 'models/label_encoder.pkl')
|
| 30 |
+
|
| 31 |
+
feature_cols = [
|
| 32 |
+
'current_task_count',
|
| 33 |
+
'avg_completion_time_days',
|
| 34 |
+
'skill_match_score',
|
| 35 |
+
'total_story_points_assigned',
|
| 36 |
+
'recent_overtime_hours',
|
| 37 |
+
'task_switch_frequency',
|
| 38 |
+
'pr_review_pending',
|
| 39 |
+
'priority',
|
| 40 |
+
'estimated_story_points',
|
| 41 |
+
'days_until_deadline',
|
| 42 |
+
'required_skill_encoded',
|
| 43 |
+
'has_dependencies',
|
| 44 |
+
'task_type',
|
| 45 |
+
'team_size',
|
| 46 |
+
'sprint_days_remaining',
|
| 47 |
+
'team_avg_velocity',
|
| 48 |
+
'workload_ratio',
|
| 49 |
+
'urgency_score',
|
| 50 |
+
'capacity_indicator',
|
| 51 |
+
'overtime_risk',
|
| 52 |
+
'skill_deficit'
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
X = df[feature_cols]
|
| 56 |
+
y = df['overload_risk']
|
| 57 |
+
|
| 58 |
+
X_train, X_test, y_train, y_test = train_test_split(
|
| 59 |
+
X, y, test_size=0.2, random_state=42, stratify=y
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
model = xgb.XGBClassifier(
|
| 63 |
+
n_estimators=200,
|
| 64 |
+
max_depth=6,
|
| 65 |
+
learning_rate=0.1,
|
| 66 |
+
subsample=0.8,
|
| 67 |
+
colsample_bytree=0.8,
|
| 68 |
+
objective='multi:softmax',
|
| 69 |
+
num_class=3,
|
| 70 |
+
random_state=42,
|
| 71 |
+
eval_metric='mlogloss',
|
| 72 |
+
tree_method='hist'
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
model.fit(X_train, y_train, verbose=False)
|
| 76 |
+
|
| 77 |
+
cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
|
| 78 |
+
cv_scores = cross_val_score(model, X_train, y_train, cv=cv, scoring='f1_weighted')
|
| 79 |
+
|
| 80 |
+
y_pred = model.predict(X_test)
|
| 81 |
+
|
| 82 |
+
accuracy = accuracy_score(y_test, y_pred)
|
| 83 |
+
f1_weighted = f1_score(y_test, y_pred, average='weighted')
|
| 84 |
+
|
| 85 |
+
print(f"Accuracy: {accuracy:.4f}")
|
| 86 |
+
print(f"F1-Score: {f1_weighted:.4f}")
|
| 87 |
+
print(f"CV F1-Score: {cv_scores.mean():.4f} (+/- {cv_scores.std():.4f})")
|
| 88 |
+
|
| 89 |
+
target_names = ['Green (0)', 'Yellow (1)', 'Red (2)']
|
| 90 |
+
print("\nClassification Report:")
|
| 91 |
+
print(classification_report(y_test, y_pred, target_names=target_names, digits=3))
|
| 92 |
+
|
| 93 |
+
print("\nConfusion Matrix:")
|
| 94 |
+
cm = confusion_matrix(y_test, y_pred)
|
| 95 |
+
print(cm)
|
| 96 |
+
|
| 97 |
+
Path('results').mkdir(exist_ok=True)
|
| 98 |
+
|
| 99 |
+
plt.figure(figsize=(8, 6))
|
| 100 |
+
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues',
|
| 101 |
+
xticklabels=target_names, yticklabels=target_names)
|
| 102 |
+
plt.title('Confusion Matrix')
|
| 103 |
+
plt.ylabel('True Label')
|
| 104 |
+
plt.xlabel('Predicted Label')
|
| 105 |
+
plt.tight_layout()
|
| 106 |
+
plt.savefig('results/confusion_matrix.png', dpi=150, bbox_inches='tight')
|
| 107 |
+
plt.close()
|
| 108 |
+
|
| 109 |
+
importance_df = pd.DataFrame({
|
| 110 |
+
'feature': feature_cols,
|
| 111 |
+
'importance': model.feature_importances_
|
| 112 |
+
}).sort_values('importance', ascending=False)
|
| 113 |
+
|
| 114 |
+
print("\nTop 10 Feature Importance:")
|
| 115 |
+
for idx, row in importance_df.head(10).iterrows():
|
| 116 |
+
print(f"{row['feature']:30s} {row['importance']:.4f}")
|
| 117 |
+
|
| 118 |
+
importance_df.to_csv('results/feature_importance.csv', index=False)
|
| 119 |
+
|
| 120 |
+
plt.figure(figsize=(10, 6))
|
| 121 |
+
top_features = importance_df.head(15)
|
| 122 |
+
plt.barh(range(len(top_features)), top_features['importance'], color='steelblue')
|
| 123 |
+
plt.yticks(range(len(top_features)), top_features['feature'])
|
| 124 |
+
plt.xlabel('Importance Score')
|
| 125 |
+
plt.title('Top 15 Feature Importance')
|
| 126 |
+
plt.gca().invert_yaxis()
|
| 127 |
+
plt.tight_layout()
|
| 128 |
+
plt.savefig('results/feature_importance.png', dpi=150, bbox_inches='tight')
|
| 129 |
+
plt.close()
|
| 130 |
+
|
| 131 |
+
joblib.dump(model, 'models/xgboost_overload_classifier.pkl')
|
| 132 |
+
|
| 133 |
+
model_metadata = {
|
| 134 |
+
'model_type': 'XGBoost Classifier',
|
| 135 |
+
'n_estimators': 200,
|
| 136 |
+
'max_depth': 6,
|
| 137 |
+
'learning_rate': 0.1,
|
| 138 |
+
'n_features': len(feature_cols),
|
| 139 |
+
'n_classes': 3,
|
| 140 |
+
'accuracy': float(accuracy),
|
| 141 |
+
'f1_score': float(f1_weighted),
|
| 142 |
+
'cv_mean': float(cv_scores.mean()),
|
| 143 |
+
'cv_std': float(cv_scores.std()),
|
| 144 |
+
'train_samples': len(X_train),
|
| 145 |
+
'test_samples': len(X_test),
|
| 146 |
+
'feature_names': feature_cols,
|
| 147 |
+
'class_names': ['Green', 'Yellow', 'Red']
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
with open('models/model_metadata.json', 'w') as f:
|
| 151 |
+
json.dump(model_metadata, f, indent=2)
|
| 152 |
+
|
| 153 |
+
print("\nTraining complete. Model saved.")
|
tests/team_workload.csv
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
developer_id,current_task_count,avg_completion_time_days,skill_match_score,total_story_points_assigned,recent_overtime_hours,task_switch_frequency,pr_review_pending,team_size,sprint_days_remaining,team_avg_velocity
|
| 2 |
+
1,8,12.0,55,30,15,6.5,8,10,5,55
|
| 3 |
+
2,3,5.5,85,12,2,2.5,1,10,5,55
|
| 4 |
+
3,10,14.0,48,35,18,7.8,12,10,5,55
|
| 5 |
+
4,2,4.0,92,8,0,1.5,2,10,5,55
|
| 6 |
+
5,5,6.5,75,18,5,3.2,3,10,5,55
|
| 7 |
+
6,4,5.0,88,15,3,2.8,4,10,5,55
|
| 8 |
+
7,6,6.0,72,22,8,4.5,5,10,5,55
|
| 9 |
+
8,1,7.0,98,3,0,1.0,1,10,5,55
|
| 10 |
+
9,7,5.5,78,26,12,5.5,7,10,5,55
|
| 11 |
+
10,3,4.5,90,11,1,2.0,2,10,5,55
|
tests/test_batch.csv
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
developer_id,current_task_count,avg_completion_time_days,skill_match_score,total_story_points_assigned,recent_overtime_hours,task_switch_frequency,pr_review_pending,priority,estimated_story_points,days_until_deadline,required_skill,has_dependencies,task_type,team_size,sprint_days_remaining,team_avg_velocity
|
| 2 |
+
5,3,5.5,85,12,2,2.5,1,1,5,10,backend,0,0,10,8,55
|
| 3 |
+
2,8,12.0,55,28,15,6.5,8,0,8,2,frontend,1,0,12,2,50
|
| 4 |
+
7,2,4.0,92,8,0,1.5,2,2,3,15,backend,0,1,10,10,60
|
| 5 |
+
9,5,6.5,95,18,5,3.2,3,1,5,7,frontend,0,0,11,7,58
|
| 6 |
+
1,10,14.0,48,35,18,7.8,12,0,13,1,ml,1,0,9,1,45
|
| 7 |
+
11,4,5.0,88,15,3,2.8,4,1,5,12,devops,0,2,10,9,52
|
| 8 |
+
6,6,6.0,72,22,8,4.5,5,1,8,5,backend,1,0,10,5,55
|
| 9 |
+
12,1,7.0,98,3,0,1.0,1,3,2,20,ml,0,1,11,12,60
|
| 10 |
+
4,7,5.5,78,26,12,5.5,7,0,8,3,testing,1,1,12,3,50
|
| 11 |
+
8,3,4.5,90,11,1,2.0,2,2,3,14,backend,0,2,10,11,57
|
utils/__init__.py
ADDED
|
File without changes
|
utils/feature_engineering.py
ADDED
|
File without changes
|
utils/visualization.py
ADDED
|
File without changes
|