Spaces:
Sleeping
Sleeping
Update code/app.py
Browse filesupdate for mobile responsiveness
- code/app.py +848 -873
code/app.py
CHANGED
|
@@ -1,873 +1,848 @@
|
|
| 1 |
-
import panel as pn
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import param
|
| 4 |
-
from bokeh.models.formatters import PrintfTickFormatter
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
return pn.widgets.tables.NumberFormatter(format="0
|
| 26 |
-
elif format_str == "%.
|
| 27 |
-
return pn.widgets.tables.NumberFormatter(format="0.
|
| 28 |
-
elif format_str == "%.
|
| 29 |
-
return pn.widgets.tables.NumberFormatter(format="0.
|
| 30 |
-
elif format_str == "
|
| 31 |
-
return pn.widgets.tables.NumberFormatter(format="
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
self.param.
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
self.param.
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
self.param.
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
self.param.
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
self.param.
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
self.param.
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
self.param.
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
self.param.
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
"
|
| 461 |
-
"
|
| 462 |
-
"
|
| 463 |
-
"
|
| 464 |
-
"
|
| 465 |
-
"
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
self.
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
)
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
self.
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
self.
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
self.
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
)
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
self.
|
| 571 |
-
self.
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
self.
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
self.
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
self.
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
self.
|
| 610 |
-
self.
|
| 611 |
-
self.
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
self.
|
| 615 |
-
self.
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
self.
|
| 641 |
-
self.
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
self.
|
| 647 |
-
self.
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
"
|
| 675 |
-
"
|
| 676 |
-
"
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
self.
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
"Per Shift":
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
),
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
pn.
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
pn.
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
),
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
),
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
pn.
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
pn.pane.Markdown("
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
)
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
pn.pane.Markdown(
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
)
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
self.
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
return main_layout
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
estimator_app = CannabinoidEstimator()
|
| 853 |
-
# To run in a Panel server:
|
| 854 |
-
# pn.config.raw_css = custom_themes.get_base_css(custom_themes.DARK_THEME_VARS)
|
| 855 |
-
estimator_app.view().servable(title="CBx Revenue Estimator")
|
| 856 |
-
|
| 857 |
-
# Instantiate the template with widgets displayed in the sidebar
|
| 858 |
-
# template = pn.template.FastListTemplate(
|
| 859 |
-
# title="CBx Revenue Estimator (FastList Panel)",
|
| 860 |
-
# #theme = custom_themes.DarkTheme,
|
| 861 |
-
# #sidebar=[freq, phase],
|
| 862 |
-
# )
|
| 863 |
-
|
| 864 |
-
# template.main.append(estimator_app.view())
|
| 865 |
-
# template.servable()
|
| 866 |
-
|
| 867 |
-
if __name__ == "__main__":
|
| 868 |
-
pn.serve(
|
| 869 |
-
estimator_app.view(),
|
| 870 |
-
title="CBx Revenue Estimator (Panel)",
|
| 871 |
-
show=True,
|
| 872 |
-
port=5007,
|
| 873 |
-
)
|
|
|
|
| 1 |
+
import panel as pn
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import param
|
| 4 |
+
from bokeh.models.formatters import PrintfTickFormatter
|
| 5 |
+
# from custom_themes import AIDefaultTheme, AIDarkTheme
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Initialize Panel extension for Tabulator and set a global sizing mode
|
| 9 |
+
pn.extension(
|
| 10 |
+
"tabulator",
|
| 11 |
+
sizing_mode="stretch_width",
|
| 12 |
+
template="fast",
|
| 13 |
+
# theme = AIDarkTheme,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# --- Styling Placeholders (as per user instruction) ---
|
| 17 |
+
slider_design = {}
|
| 18 |
+
slider_style = {}
|
| 19 |
+
slider_stylesheet = []
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# --- Helper for NumberFormatters ---
|
| 23 |
+
def get_formatter(format_str):
|
| 24 |
+
if format_str == "%i":
|
| 25 |
+
return pn.widgets.tables.NumberFormatter(format="0")
|
| 26 |
+
elif format_str == "%.1f":
|
| 27 |
+
return pn.widgets.tables.NumberFormatter(format="0.0")
|
| 28 |
+
elif format_str == "%.2f":
|
| 29 |
+
return pn.widgets.tables.NumberFormatter(format="0.00")
|
| 30 |
+
elif format_str == "%.4f":
|
| 31 |
+
return pn.widgets.tables.NumberFormatter(format="0.0000")
|
| 32 |
+
elif format_str == "$%.02f":
|
| 33 |
+
return pn.widgets.tables.NumberFormatter(format="$0,0.00")
|
| 34 |
+
return format_str
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class CannabinoidEstimator(param.Parameterized):
|
| 38 |
+
# --- Input Parameters ---
|
| 39 |
+
kg_processed_per_hour = param.Number(
|
| 40 |
+
default=150.0,
|
| 41 |
+
bounds=(0, 2000),
|
| 42 |
+
step=1.0,
|
| 43 |
+
label="Biomass processed per hour (kg)",
|
| 44 |
+
)
|
| 45 |
+
finished_product_yield_pct = param.Number(
|
| 46 |
+
default=60.0,
|
| 47 |
+
bounds=(0.01, 100),
|
| 48 |
+
step=0.01,
|
| 49 |
+
label="Product yield: CBx Weight Output / Weight Input (%)",
|
| 50 |
+
)
|
| 51 |
+
kwh_rate = param.Number(
|
| 52 |
+
default=0.25, bounds=(0.01, 5), step=0.01, label="Power rate ($ per kWh)"
|
| 53 |
+
)
|
| 54 |
+
water_cost_per_1000l = param.Number(
|
| 55 |
+
default=2.50,
|
| 56 |
+
bounds=(0.01, 10),
|
| 57 |
+
step=0.01,
|
| 58 |
+
label="Water rate ($ per 1000L / m3)",
|
| 59 |
+
)
|
| 60 |
+
consumables_per_kg_bio_rate = param.Number(
|
| 61 |
+
default=0.0032,
|
| 62 |
+
bounds=(0, 10),
|
| 63 |
+
step=0.0001,
|
| 64 |
+
label="Other Consumables rate ($ per kg biomass)",
|
| 65 |
+
)
|
| 66 |
+
kwh_per_kg_bio = param.Number(
|
| 67 |
+
default=0.25,
|
| 68 |
+
bounds=(0.05, 15),
|
| 69 |
+
step=0.01,
|
| 70 |
+
label="Power consumption (kWh per kg biomass)",
|
| 71 |
+
)
|
| 72 |
+
water_liters_consumed_per_kg_bio = param.Number(
|
| 73 |
+
default=3.0,
|
| 74 |
+
bounds=(0.1, 100),
|
| 75 |
+
step=0.1,
|
| 76 |
+
label="Water consumption (liters per kg biomass)",
|
| 77 |
+
)
|
| 78 |
+
consumables_per_kg_output = param.Number(
|
| 79 |
+
default=10.0,
|
| 80 |
+
bounds=(0, 100),
|
| 81 |
+
step=0.01,
|
| 82 |
+
label="Consumables per kg finished product ($)",
|
| 83 |
+
)
|
| 84 |
+
bio_cbx_pct = param.Number(
|
| 85 |
+
default=10.0, bounds=(0, 30), step=0.1, label="Cannabinoid (CBx) in biomass (%)"
|
| 86 |
+
)
|
| 87 |
+
bio_cost = param.Number(
|
| 88 |
+
default=3.0,
|
| 89 |
+
bounds=(0, 200),
|
| 90 |
+
step=0.25,
|
| 91 |
+
label="Biomass purchase cost ($ per kg)",
|
| 92 |
+
)
|
| 93 |
+
wholesale_cbx_price = param.Number(
|
| 94 |
+
default=220.0,
|
| 95 |
+
bounds=(25, 6000),
|
| 96 |
+
step=5.0,
|
| 97 |
+
label="Gross revenue ($ per kg output)",
|
| 98 |
+
)
|
| 99 |
+
wholesale_cbx_pct = param.Number(
|
| 100 |
+
default=99.9, bounds=(0, 100), step=0.01, label="CBx in finished product (%)"
|
| 101 |
+
)
|
| 102 |
+
batch_test_cost = param.Number(
|
| 103 |
+
default=1300.0,
|
| 104 |
+
bounds=(100, 5000),
|
| 105 |
+
step=25.0,
|
| 106 |
+
label="Per-batch testing/compliance costs ($)",
|
| 107 |
+
)
|
| 108 |
+
fixed_overhead_per_week = param.Number(
|
| 109 |
+
default=2000.0, bounds=(0, 10000), step=1.0, label="Weekly fixed costs ($)"
|
| 110 |
+
)
|
| 111 |
+
workers_per_shift = param.Number(
|
| 112 |
+
default=9.0, bounds=(1, 20), step=1.0, label="Workers per shift"
|
| 113 |
+
)
|
| 114 |
+
worker_hourly_rate = param.Number(
|
| 115 |
+
default=5.0, bounds=(0.25, 50), step=0.25, label="Worker loaded pay rate ($/hr)"
|
| 116 |
+
)
|
| 117 |
+
managers_per_shift = param.Number(
|
| 118 |
+
default=1.0, bounds=(1, 10), step=1.0, label="Supervisors per shift"
|
| 119 |
+
)
|
| 120 |
+
manager_hourly_rate = param.Number(
|
| 121 |
+
default=10.0,
|
| 122 |
+
bounds=(5.0, 50),
|
| 123 |
+
step=0.25,
|
| 124 |
+
label="Supervisor loaded pay rate ($/hr)",
|
| 125 |
+
)
|
| 126 |
+
processing_hours_per_shift = param.Number(
|
| 127 |
+
default=7.0, bounds=(0.25, 8.0), step=0.25, label="Processing hours per shift"
|
| 128 |
+
)
|
| 129 |
+
labour_hours_per_shift = param.Number(
|
| 130 |
+
default=8.0, bounds=(6.0, 12), step=0.25, label="Labor hours per shift"
|
| 131 |
+
)
|
| 132 |
+
shifts_per_day = param.Number(
|
| 133 |
+
default=3.0, bounds=(1, 10), step=1.0, label="Shifts per day"
|
| 134 |
+
)
|
| 135 |
+
shifts_per_week = param.Number(
|
| 136 |
+
default=21.0, bounds=(1, 28), step=1.0, label="Shifts per week"
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
kg_processed_per_shift = 0.0
|
| 140 |
+
labour_cost_per_shift = 0.0
|
| 141 |
+
variable_cost_per_shift = 0.0
|
| 142 |
+
overhead_cost_per_shift = 0.0
|
| 143 |
+
saleable_kg_per_kg_bio = 0.0
|
| 144 |
+
saleable_kg_per_shift = 0.0
|
| 145 |
+
saleable_kg_per_day = 0.0
|
| 146 |
+
saleable_kg_per_week = 0.0
|
| 147 |
+
biomass_kg_per_saleable_kg = 0.0
|
| 148 |
+
internal_cogs_per_kg_bio = 0.0
|
| 149 |
+
internal_cogs_per_shift = 0.0
|
| 150 |
+
internal_cogs_per_day = 0.0
|
| 151 |
+
internal_cogs_per_week = 0.0
|
| 152 |
+
internal_cogs_per_kg_output = 0.0
|
| 153 |
+
biomass_cost_per_shift = 0.0
|
| 154 |
+
biomass_cost_per_day = 0.0
|
| 155 |
+
biomass_cost_per_week = 0.0
|
| 156 |
+
biomass_cost_per_kg_output = 0.0
|
| 157 |
+
gross_rev_per_kg_bio = 0.0
|
| 158 |
+
gross_rev_per_shift = 0.0
|
| 159 |
+
gross_rev_per_day = 0.0
|
| 160 |
+
gross_rev_per_week = 0.0
|
| 161 |
+
net_rev_per_kg_bio = 0.0
|
| 162 |
+
net_rev_per_shift = 0.0
|
| 163 |
+
net_rev_per_day = 0.0
|
| 164 |
+
net_rev_per_week = 0.0
|
| 165 |
+
net_rev_per_kg_output = 0.0
|
| 166 |
+
operating_profit_pct = 0.0
|
| 167 |
+
resin_spread_pct = 0.0
|
| 168 |
+
|
| 169 |
+
money_data_df = param.DataFrame(pd.DataFrame())
|
| 170 |
+
profit_data_df = param.DataFrame(pd.DataFrame())
|
| 171 |
+
processing_data_df = param.DataFrame(pd.DataFrame())
|
| 172 |
+
|
| 173 |
+
def __init__(self, **params):
|
| 174 |
+
super().__init__(**params)
|
| 175 |
+
self._create_sliders()
|
| 176 |
+
self.money_table = pn.widgets.Tabulator(
|
| 177 |
+
self.money_data_df,
|
| 178 |
+
formatters=self._get_money_formatters(),
|
| 179 |
+
disabled=True,
|
| 180 |
+
layout="fit_data",
|
| 181 |
+
sizing_mode="fixed",
|
| 182 |
+
align="center",
|
| 183 |
+
show_index=False, # Hide index column
|
| 184 |
+
text_align={
|
| 185 |
+
" ": "right",
|
| 186 |
+
"$/kg Biomass": "center",
|
| 187 |
+
"$/kg Output": "center",
|
| 188 |
+
"Per Shift": "center",
|
| 189 |
+
"Per Day": "center",
|
| 190 |
+
"Per Week": "center",
|
| 191 |
+
},
|
| 192 |
+
)
|
| 193 |
+
self.profit_table = pn.widgets.Tabulator(
|
| 194 |
+
self.profit_data_df,
|
| 195 |
+
disabled=True,
|
| 196 |
+
layout="fit_data_table",
|
| 197 |
+
sizing_mode="fixed",
|
| 198 |
+
align="center",
|
| 199 |
+
show_index=False, # Hide index column
|
| 200 |
+
text_align={
|
| 201 |
+
"Metric": "right",
|
| 202 |
+
"Value": "center",
|
| 203 |
+
},
|
| 204 |
+
)
|
| 205 |
+
self.processing_table = pn.widgets.Tabulator(
|
| 206 |
+
self.processing_data_df,
|
| 207 |
+
formatters={},
|
| 208 |
+
disabled=True,
|
| 209 |
+
layout="fit_data_table",
|
| 210 |
+
sizing_mode="fixed",
|
| 211 |
+
align="center",
|
| 212 |
+
show_index=False, # Hide index column
|
| 213 |
+
text_align={
|
| 214 |
+
"Metric (Per Shift)": "right",
|
| 215 |
+
"Value": "center",
|
| 216 |
+
},
|
| 217 |
+
)
|
| 218 |
+
self._update_calculations()
|
| 219 |
+
|
| 220 |
+
def _create_sliders(self):
|
| 221 |
+
self.kg_processed_per_hour_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 222 |
+
self.param.kg_processed_per_hour,
|
| 223 |
+
name=self.param.kg_processed_per_hour.label,
|
| 224 |
+
fixed_start=self.param.kg_processed_per_hour.bounds[0],
|
| 225 |
+
fixed_end=self.param.kg_processed_per_hour.bounds[1],
|
| 226 |
+
design=slider_design,
|
| 227 |
+
styles=slider_style,
|
| 228 |
+
stylesheets=slider_stylesheet,
|
| 229 |
+
# format="0",
|
| 230 |
+
format=PrintfTickFormatter(format="%i kg"),
|
| 231 |
+
)
|
| 232 |
+
self.finished_product_yield_pct_slider = (
|
| 233 |
+
pn.widgets.EditableFloatSlider.from_param(
|
| 234 |
+
self.param.finished_product_yield_pct,
|
| 235 |
+
name=self.param.finished_product_yield_pct.label,
|
| 236 |
+
fixed_start=self.param.finished_product_yield_pct.bounds[0],
|
| 237 |
+
fixed_end=self.param.finished_product_yield_pct.bounds[1],
|
| 238 |
+
design=slider_design,
|
| 239 |
+
styles=slider_style,
|
| 240 |
+
stylesheets=slider_stylesheet,
|
| 241 |
+
format="0.00",
|
| 242 |
+
)
|
| 243 |
+
)
|
| 244 |
+
self.kwh_rate_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 245 |
+
self.param.kwh_rate,
|
| 246 |
+
name=self.param.kwh_rate.label,
|
| 247 |
+
fixed_start=self.param.kwh_rate.bounds[0],
|
| 248 |
+
fixed_end=self.param.kwh_rate.bounds[1],
|
| 249 |
+
design=slider_design,
|
| 250 |
+
styles=slider_style,
|
| 251 |
+
stylesheets=slider_stylesheet,
|
| 252 |
+
format="0.00",
|
| 253 |
+
# format=PrintfTickFormatter(format='%.2f per kWh'),
|
| 254 |
+
)
|
| 255 |
+
self.water_cost_per_1000l_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 256 |
+
self.param.water_cost_per_1000l,
|
| 257 |
+
name=self.param.water_cost_per_1000l.label,
|
| 258 |
+
fixed_start=self.param.water_cost_per_1000l.bounds[0],
|
| 259 |
+
fixed_end=self.param.water_cost_per_1000l.bounds[1],
|
| 260 |
+
design=slider_design,
|
| 261 |
+
styles=slider_style,
|
| 262 |
+
stylesheets=slider_stylesheet,
|
| 263 |
+
format="0.00",
|
| 264 |
+
)
|
| 265 |
+
self.consumables_per_kg_bio_rate_slider = (
|
| 266 |
+
pn.widgets.EditableFloatSlider.from_param(
|
| 267 |
+
self.param.consumables_per_kg_bio_rate,
|
| 268 |
+
name=self.param.consumables_per_kg_bio_rate.label,
|
| 269 |
+
fixed_start=self.param.consumables_per_kg_bio_rate.bounds[0],
|
| 270 |
+
fixed_end=self.param.consumables_per_kg_bio_rate.bounds[1],
|
| 271 |
+
design=slider_design,
|
| 272 |
+
styles=slider_style,
|
| 273 |
+
stylesheets=slider_stylesheet,
|
| 274 |
+
format="0.0000",
|
| 275 |
+
)
|
| 276 |
+
)
|
| 277 |
+
self.kwh_per_kg_bio_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 278 |
+
self.param.kwh_per_kg_bio,
|
| 279 |
+
name=self.param.kwh_per_kg_bio.label,
|
| 280 |
+
fixed_start=self.param.kwh_per_kg_bio.bounds[0],
|
| 281 |
+
fixed_end=self.param.kwh_per_kg_bio.bounds[1],
|
| 282 |
+
design=slider_design,
|
| 283 |
+
styles=slider_style,
|
| 284 |
+
stylesheets=slider_stylesheet,
|
| 285 |
+
format="0.00",
|
| 286 |
+
)
|
| 287 |
+
self.water_liters_consumed_per_kg_bio_slider = (
|
| 288 |
+
pn.widgets.EditableFloatSlider.from_param(
|
| 289 |
+
self.param.water_liters_consumed_per_kg_bio,
|
| 290 |
+
name=self.param.water_liters_consumed_per_kg_bio.label,
|
| 291 |
+
fixed_start=self.param.water_liters_consumed_per_kg_bio.bounds[0],
|
| 292 |
+
fixed_end=self.param.water_liters_consumed_per_kg_bio.bounds[1],
|
| 293 |
+
design=slider_design,
|
| 294 |
+
styles=slider_style,
|
| 295 |
+
stylesheets=slider_stylesheet,
|
| 296 |
+
format="0.0",
|
| 297 |
+
)
|
| 298 |
+
)
|
| 299 |
+
self.consumables_per_kg_output_slider = (
|
| 300 |
+
pn.widgets.EditableFloatSlider.from_param(
|
| 301 |
+
self.param.consumables_per_kg_output,
|
| 302 |
+
name=self.param.consumables_per_kg_output.label,
|
| 303 |
+
fixed_start=self.param.consumables_per_kg_output.bounds[0],
|
| 304 |
+
fixed_end=self.param.consumables_per_kg_output.bounds[1],
|
| 305 |
+
design=slider_design,
|
| 306 |
+
styles=slider_style,
|
| 307 |
+
stylesheets=slider_stylesheet,
|
| 308 |
+
format="0.00",
|
| 309 |
+
)
|
| 310 |
+
)
|
| 311 |
+
self.bio_cbx_pct_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 312 |
+
self.param.bio_cbx_pct,
|
| 313 |
+
name=self.param.bio_cbx_pct.label,
|
| 314 |
+
fixed_start=self.param.bio_cbx_pct.bounds[0],
|
| 315 |
+
fixed_end=self.param.bio_cbx_pct.bounds[1],
|
| 316 |
+
design=slider_design,
|
| 317 |
+
styles=slider_style,
|
| 318 |
+
stylesheets=slider_stylesheet,
|
| 319 |
+
format="0.0",
|
| 320 |
+
)
|
| 321 |
+
self.bio_cost_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 322 |
+
self.param.bio_cost,
|
| 323 |
+
name=self.param.bio_cost.label,
|
| 324 |
+
fixed_start=self.param.bio_cost.bounds[0],
|
| 325 |
+
fixed_end=self.param.bio_cost.bounds[1],
|
| 326 |
+
design=slider_design,
|
| 327 |
+
styles=slider_style,
|
| 328 |
+
stylesheets=slider_stylesheet,
|
| 329 |
+
format="0.00",
|
| 330 |
+
)
|
| 331 |
+
self.wholesale_cbx_price_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 332 |
+
self.param.wholesale_cbx_price,
|
| 333 |
+
name=self.param.wholesale_cbx_price.label,
|
| 334 |
+
fixed_start=self.param.wholesale_cbx_price.bounds[0],
|
| 335 |
+
fixed_end=self.param.wholesale_cbx_price.bounds[1],
|
| 336 |
+
design=slider_design,
|
| 337 |
+
styles=slider_style,
|
| 338 |
+
stylesheets=slider_stylesheet,
|
| 339 |
+
format="0",
|
| 340 |
+
)
|
| 341 |
+
self.wholesale_cbx_pct_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 342 |
+
self.param.wholesale_cbx_pct,
|
| 343 |
+
name=self.param.wholesale_cbx_pct.label,
|
| 344 |
+
fixed_start=self.param.wholesale_cbx_pct.bounds[0],
|
| 345 |
+
fixed_end=self.param.wholesale_cbx_pct.bounds[1],
|
| 346 |
+
design=slider_design,
|
| 347 |
+
styles=slider_style,
|
| 348 |
+
stylesheets=slider_stylesheet,
|
| 349 |
+
format="0.00",
|
| 350 |
+
)
|
| 351 |
+
self.batch_test_cost_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 352 |
+
self.param.batch_test_cost,
|
| 353 |
+
name=self.param.batch_test_cost.label,
|
| 354 |
+
fixed_start=self.param.batch_test_cost.bounds[0],
|
| 355 |
+
fixed_end=self.param.batch_test_cost.bounds[1],
|
| 356 |
+
design=slider_design,
|
| 357 |
+
styles=slider_style,
|
| 358 |
+
stylesheets=slider_stylesheet,
|
| 359 |
+
format="0",
|
| 360 |
+
)
|
| 361 |
+
self.fixed_overhead_per_week_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 362 |
+
self.param.fixed_overhead_per_week,
|
| 363 |
+
name=self.param.fixed_overhead_per_week.label,
|
| 364 |
+
fixed_start=self.param.fixed_overhead_per_week.bounds[0],
|
| 365 |
+
fixed_end=self.param.fixed_overhead_per_week.bounds[1],
|
| 366 |
+
design=slider_design,
|
| 367 |
+
styles=slider_style,
|
| 368 |
+
stylesheets=slider_stylesheet,
|
| 369 |
+
format="0",
|
| 370 |
+
)
|
| 371 |
+
self.workers_per_shift_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 372 |
+
self.param.workers_per_shift,
|
| 373 |
+
name=self.param.workers_per_shift.label,
|
| 374 |
+
fixed_start=self.param.workers_per_shift.bounds[0],
|
| 375 |
+
fixed_end=self.param.workers_per_shift.bounds[1],
|
| 376 |
+
design=slider_design,
|
| 377 |
+
styles=slider_style,
|
| 378 |
+
stylesheets=slider_stylesheet,
|
| 379 |
+
format="0",
|
| 380 |
+
)
|
| 381 |
+
self.worker_hourly_rate_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 382 |
+
self.param.worker_hourly_rate,
|
| 383 |
+
name=self.param.worker_hourly_rate.label,
|
| 384 |
+
fixed_start=self.param.worker_hourly_rate.bounds[0],
|
| 385 |
+
fixed_end=self.param.worker_hourly_rate.bounds[1],
|
| 386 |
+
design=slider_design,
|
| 387 |
+
styles=slider_style,
|
| 388 |
+
stylesheets=slider_stylesheet,
|
| 389 |
+
format="0.00",
|
| 390 |
+
)
|
| 391 |
+
self.managers_per_shift_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 392 |
+
self.param.managers_per_shift,
|
| 393 |
+
name=self.param.managers_per_shift.label,
|
| 394 |
+
fixed_start=self.param.managers_per_shift.bounds[0],
|
| 395 |
+
fixed_end=self.param.managers_per_shift.bounds[1],
|
| 396 |
+
design=slider_design,
|
| 397 |
+
styles=slider_style,
|
| 398 |
+
stylesheets=slider_stylesheet,
|
| 399 |
+
format="0",
|
| 400 |
+
)
|
| 401 |
+
self.manager_hourly_rate_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 402 |
+
self.param.manager_hourly_rate,
|
| 403 |
+
name=self.param.manager_hourly_rate.label,
|
| 404 |
+
fixed_start=self.param.worker_hourly_rate.default, # Keeping original logic as per file
|
| 405 |
+
fixed_end=self.param.manager_hourly_rate.bounds[1],
|
| 406 |
+
design=slider_design,
|
| 407 |
+
styles=slider_style,
|
| 408 |
+
stylesheets=slider_stylesheet,
|
| 409 |
+
format="0.00",
|
| 410 |
+
)
|
| 411 |
+
|
| 412 |
+
self.labour_hours_per_shift_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 413 |
+
self.param.labour_hours_per_shift,
|
| 414 |
+
name=self.param.labour_hours_per_shift.label,
|
| 415 |
+
fixed_start=self.param.labour_hours_per_shift.bounds[
|
| 416 |
+
0
|
| 417 |
+
], # Changed in previous request
|
| 418 |
+
fixed_end=self.param.labour_hours_per_shift.bounds[1],
|
| 419 |
+
design=slider_design,
|
| 420 |
+
styles=slider_style,
|
| 421 |
+
stylesheets=slider_stylesheet,
|
| 422 |
+
format="0.00",
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
self.processing_hours_per_shift_slider = (
|
| 426 |
+
pn.widgets.EditableFloatSlider.from_param(
|
| 427 |
+
self.param.processing_hours_per_shift,
|
| 428 |
+
name=self.param.processing_hours_per_shift.label,
|
| 429 |
+
fixed_start=self.param.processing_hours_per_shift.bounds[0],
|
| 430 |
+
fixed_end=self.labour_hours_per_shift, # Changed in previous request
|
| 431 |
+
design=slider_design,
|
| 432 |
+
styles=slider_style,
|
| 433 |
+
stylesheets=slider_stylesheet,
|
| 434 |
+
format="0.00",
|
| 435 |
+
)
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
+
self.shifts_per_day_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 439 |
+
self.param.shifts_per_day,
|
| 440 |
+
name=self.param.shifts_per_day.label,
|
| 441 |
+
fixed_start=self.param.shifts_per_day.bounds[0],
|
| 442 |
+
fixed_end=self.param.shifts_per_day.bounds[1],
|
| 443 |
+
design=slider_design,
|
| 444 |
+
styles=slider_style,
|
| 445 |
+
stylesheets=slider_stylesheet,
|
| 446 |
+
format="0",
|
| 447 |
+
)
|
| 448 |
+
self.shifts_per_week_slider = pn.widgets.EditableFloatSlider.from_param(
|
| 449 |
+
self.param.shifts_per_week,
|
| 450 |
+
name=self.param.shifts_per_week.label,
|
| 451 |
+
fixed_start=self.param.shifts_per_week.bounds[0],
|
| 452 |
+
fixed_end=self.param.shifts_per_week.bounds[1],
|
| 453 |
+
design=slider_design,
|
| 454 |
+
styles=slider_style,
|
| 455 |
+
stylesheets=slider_stylesheet,
|
| 456 |
+
format="0",
|
| 457 |
+
)
|
| 458 |
+
|
| 459 |
+
@param.depends(
|
| 460 |
+
"kg_processed_per_hour",
|
| 461 |
+
"finished_product_yield_pct",
|
| 462 |
+
"kwh_rate",
|
| 463 |
+
"water_cost_per_1000l",
|
| 464 |
+
"consumables_per_kg_bio_rate",
|
| 465 |
+
"kwh_per_kg_bio",
|
| 466 |
+
"water_liters_consumed_per_kg_bio",
|
| 467 |
+
"consumables_per_kg_output",
|
| 468 |
+
"bio_cbx_pct",
|
| 469 |
+
"bio_cost",
|
| 470 |
+
"wholesale_cbx_price",
|
| 471 |
+
"wholesale_cbx_pct",
|
| 472 |
+
"batch_test_cost",
|
| 473 |
+
"fixed_overhead_per_week",
|
| 474 |
+
"workers_per_shift",
|
| 475 |
+
"worker_hourly_rate",
|
| 476 |
+
"managers_per_shift",
|
| 477 |
+
"manager_hourly_rate",
|
| 478 |
+
"labour_hours_per_shift",
|
| 479 |
+
"processing_hours_per_shift",
|
| 480 |
+
"shifts_per_day",
|
| 481 |
+
"shifts_per_week",
|
| 482 |
+
watch=True,
|
| 483 |
+
)
|
| 484 |
+
def _update_calculations(self, *events):
|
| 485 |
+
self.kg_processed_per_shift = (
|
| 486 |
+
self.processing_hours_per_shift * self.kg_processed_per_hour
|
| 487 |
+
)
|
| 488 |
+
if self.shifts_per_week == 0:
|
| 489 |
+
self.shifts_per_week = 1
|
| 490 |
+
|
| 491 |
+
self._calc_saleable_kg()
|
| 492 |
+
self._calc_biomass_cost()
|
| 493 |
+
self._calc_cogs()
|
| 494 |
+
self._calc_gross_revenue()
|
| 495 |
+
self._calc_net_revenue()
|
| 496 |
+
|
| 497 |
+
self.operating_profit_pct = (
|
| 498 |
+
(self.net_rev_per_kg_bio / self.gross_rev_per_kg_bio)
|
| 499 |
+
if self.gross_rev_per_kg_bio
|
| 500 |
+
else 0.0
|
| 501 |
+
)
|
| 502 |
+
self.resin_spread_pct = (
|
| 503 |
+
((self.gross_rev_per_kg_bio - self.bio_cost) / self.bio_cost)
|
| 504 |
+
if self.bio_cost
|
| 505 |
+
else 0.0
|
| 506 |
+
)
|
| 507 |
+
|
| 508 |
+
self._update_tables_data()
|
| 509 |
+
|
| 510 |
+
@param.depends("labour_hours_per_shift", watch=True)
|
| 511 |
+
def _update_processing_hours_slider_constraints(self):
|
| 512 |
+
new_max_processing_hours = self.labour_hours_per_shift
|
| 513 |
+
|
| 514 |
+
# Get the current lower bound of the processing_hours_per_shift parameter
|
| 515 |
+
current_min_processing_hours = self.param.processing_hours_per_shift.bounds[0]
|
| 516 |
+
|
| 517 |
+
# Update the bounds of the underlying param.Number object for processing_hours_per_shift
|
| 518 |
+
# This allows the parameter to accept values up to the new maximum
|
| 519 |
+
self.param.processing_hours_per_shift.bounds = (
|
| 520 |
+
current_min_processing_hours,
|
| 521 |
+
new_max_processing_hours,
|
| 522 |
+
)
|
| 523 |
+
|
| 524 |
+
# Ensure the slider widget has been created before trying to access it
|
| 525 |
+
if hasattr(self, "processing_hours_per_shift_slider"):
|
| 526 |
+
# Update the 'end' property of the slider widget
|
| 527 |
+
self.processing_hours_per_shift_slider.end = new_max_processing_hours
|
| 528 |
+
|
| 529 |
+
# If the current value of processing_hours_per_shift is now greater than
|
| 530 |
+
# the new maximum, adjust it to be the new maximum.
|
| 531 |
+
if self.processing_hours_per_shift > new_max_processing_hours:
|
| 532 |
+
self.processing_hours_per_shift = new_max_processing_hours
|
| 533 |
+
|
| 534 |
+
def _calc_cogs(self):
|
| 535 |
+
worker_cost = self.workers_per_shift * self.worker_hourly_rate
|
| 536 |
+
manager_cost = self.managers_per_shift * self.manager_hourly_rate
|
| 537 |
+
self.labour_cost_per_shift = (
|
| 538 |
+
worker_cost + manager_cost
|
| 539 |
+
) * self.labour_hours_per_shift
|
| 540 |
+
|
| 541 |
+
power_cost_per_kg = self.kwh_rate * self.kwh_per_kg_bio
|
| 542 |
+
water_cost_per_kg = (
|
| 543 |
+
self.water_cost_per_1000l / 1000.0
|
| 544 |
+
) * self.water_liters_consumed_per_kg_bio
|
| 545 |
+
total_variable_consumable_cost_per_kg = (
|
| 546 |
+
self.consumables_per_kg_bio_rate + power_cost_per_kg + water_cost_per_kg
|
| 547 |
+
)
|
| 548 |
+
self.variable_cost_per_shift = (
|
| 549 |
+
total_variable_consumable_cost_per_kg * self.kg_processed_per_shift
|
| 550 |
+
)
|
| 551 |
+
|
| 552 |
+
self.overhead_cost_per_shift = (
|
| 553 |
+
self.fixed_overhead_per_week / self.shifts_per_week
|
| 554 |
+
if self.shifts_per_week > 0
|
| 555 |
+
else 0.0
|
| 556 |
+
)
|
| 557 |
+
|
| 558 |
+
shift_cogs_before_output_specific = (
|
| 559 |
+
self.labour_cost_per_shift
|
| 560 |
+
+ self.variable_cost_per_shift
|
| 561 |
+
+ self.overhead_cost_per_shift
|
| 562 |
+
)
|
| 563 |
+
shift_output_specific_cogs = (
|
| 564 |
+
self.consumables_per_kg_output * self.saleable_kg_per_shift
|
| 565 |
+
)
|
| 566 |
+
|
| 567 |
+
self.internal_cogs_per_shift = (
|
| 568 |
+
shift_cogs_before_output_specific + shift_output_specific_cogs
|
| 569 |
+
)
|
| 570 |
+
self.internal_cogs_per_kg_bio = (
|
| 571 |
+
self.internal_cogs_per_shift / self.kg_processed_per_shift
|
| 572 |
+
if self.kg_processed_per_shift > 0
|
| 573 |
+
else 0.0
|
| 574 |
+
)
|
| 575 |
+
self.internal_cogs_per_day = self.internal_cogs_per_shift * self.shifts_per_day
|
| 576 |
+
self.internal_cogs_per_week = (
|
| 577 |
+
self.internal_cogs_per_shift * self.shifts_per_week
|
| 578 |
+
)
|
| 579 |
+
self.internal_cogs_per_kg_output = (
|
| 580 |
+
(self.internal_cogs_per_kg_bio * self.biomass_kg_per_saleable_kg)
|
| 581 |
+
if self.biomass_kg_per_saleable_kg != 0
|
| 582 |
+
else 0.0
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
def _calc_gross_revenue(self):
|
| 586 |
+
self.gross_rev_per_kg_bio = (
|
| 587 |
+
self.saleable_kg_per_kg_bio * self.wholesale_cbx_price
|
| 588 |
+
)
|
| 589 |
+
self.gross_rev_per_shift = (
|
| 590 |
+
self.gross_rev_per_kg_bio * self.kg_processed_per_shift
|
| 591 |
+
)
|
| 592 |
+
self.gross_rev_per_day = self.gross_rev_per_shift * self.shifts_per_day
|
| 593 |
+
self.gross_rev_per_week = self.gross_rev_per_shift * self.shifts_per_week
|
| 594 |
+
|
| 595 |
+
def _calc_net_revenue(self):
|
| 596 |
+
self.net_rev_per_kg_bio = (
|
| 597 |
+
self.gross_rev_per_kg_bio - self.internal_cogs_per_kg_bio - self.bio_cost
|
| 598 |
+
)
|
| 599 |
+
self.net_rev_per_shift = self.net_rev_per_kg_bio * self.kg_processed_per_shift
|
| 600 |
+
self.net_rev_per_day = self.net_rev_per_shift * self.shifts_per_day
|
| 601 |
+
self.net_rev_per_week = self.net_rev_per_shift * self.shifts_per_week
|
| 602 |
+
self.net_rev_per_kg_output = (
|
| 603 |
+
(self.biomass_kg_per_saleable_kg * self.net_rev_per_kg_bio)
|
| 604 |
+
if self.biomass_kg_per_saleable_kg != 0
|
| 605 |
+
else 0.0
|
| 606 |
+
)
|
| 607 |
+
|
| 608 |
+
def _calc_biomass_cost(self):
|
| 609 |
+
self.biomass_cost_per_shift = self.kg_processed_per_shift * self.bio_cost
|
| 610 |
+
self.biomass_cost_per_day = self.biomass_cost_per_shift * self.shifts_per_day
|
| 611 |
+
self.biomass_cost_per_week = self.biomass_cost_per_shift * self.shifts_per_week
|
| 612 |
+
|
| 613 |
+
def _calc_saleable_kg(self):
|
| 614 |
+
if self.wholesale_cbx_pct == 0:
|
| 615 |
+
self.saleable_kg_per_kg_bio = 0.0
|
| 616 |
+
else:
|
| 617 |
+
self.saleable_kg_per_kg_bio = (
|
| 618 |
+
(self.bio_cbx_pct / 100.0)
|
| 619 |
+
* (self.finished_product_yield_pct / 100.0)
|
| 620 |
+
/ (self.wholesale_cbx_pct / 100.0)
|
| 621 |
+
)
|
| 622 |
+
self.saleable_kg_per_shift = (
|
| 623 |
+
self.saleable_kg_per_kg_bio * self.kg_processed_per_shift
|
| 624 |
+
)
|
| 625 |
+
self.saleable_kg_per_day = self.saleable_kg_per_shift * self.shifts_per_day
|
| 626 |
+
self.saleable_kg_per_week = self.saleable_kg_per_shift * self.shifts_per_week
|
| 627 |
+
self.biomass_kg_per_saleable_kg = (
|
| 628 |
+
1 / self.saleable_kg_per_kg_bio if self.saleable_kg_per_kg_bio > 0 else 0.0
|
| 629 |
+
)
|
| 630 |
+
self.biomass_cost_per_kg_output = (
|
| 631 |
+
self.biomass_kg_per_saleable_kg * self.bio_cost
|
| 632 |
+
)
|
| 633 |
+
|
| 634 |
+
def _update_tables_data(self):
|
| 635 |
+
money_data_dict = {
|
| 636 |
+
" ": ["Biomass cost", "Processing cost", "Gross Revenue", "Net Revenue"],
|
| 637 |
+
"$/kg Biomass": [
|
| 638 |
+
self.bio_cost,
|
| 639 |
+
self.internal_cogs_per_kg_bio,
|
| 640 |
+
self.gross_rev_per_kg_bio,
|
| 641 |
+
self.net_rev_per_kg_bio,
|
| 642 |
+
],
|
| 643 |
+
"$/kg Output": [
|
| 644 |
+
self.biomass_cost_per_kg_output,
|
| 645 |
+
self.internal_cogs_per_kg_output,
|
| 646 |
+
self.wholesale_cbx_price,
|
| 647 |
+
self.net_rev_per_kg_output,
|
| 648 |
+
],
|
| 649 |
+
"Per Shift": [
|
| 650 |
+
self.biomass_cost_per_shift,
|
| 651 |
+
self.internal_cogs_per_shift,
|
| 652 |
+
self.gross_rev_per_shift,
|
| 653 |
+
self.net_rev_per_shift,
|
| 654 |
+
],
|
| 655 |
+
"Per Day": [
|
| 656 |
+
self.biomass_cost_per_day,
|
| 657 |
+
self.internal_cogs_per_day,
|
| 658 |
+
self.gross_rev_per_day,
|
| 659 |
+
self.net_rev_per_day,
|
| 660 |
+
],
|
| 661 |
+
"Per Week": [
|
| 662 |
+
self.biomass_cost_per_week,
|
| 663 |
+
self.internal_cogs_per_week,
|
| 664 |
+
self.gross_rev_per_week,
|
| 665 |
+
self.net_rev_per_week,
|
| 666 |
+
],
|
| 667 |
+
}
|
| 668 |
+
self.money_data_df = pd.DataFrame(money_data_dict)
|
| 669 |
+
if hasattr(self, "money_table"):
|
| 670 |
+
self.money_table.value = self.money_data_df
|
| 671 |
+
|
| 672 |
+
profit_data_dict = {
|
| 673 |
+
"Metric": ["Operating Profit", "Resin Spread"],
|
| 674 |
+
"Value": [
|
| 675 |
+
f"{self.operating_profit_pct * 100.0:.2f}%",
|
| 676 |
+
f"{self.resin_spread_pct * 100.0:.2f}%",
|
| 677 |
+
],
|
| 678 |
+
}
|
| 679 |
+
self.profit_data_df = pd.DataFrame(profit_data_dict)
|
| 680 |
+
if hasattr(self, "profit_table"):
|
| 681 |
+
self.profit_table.value = self.profit_data_df
|
| 682 |
+
|
| 683 |
+
processing_values_formatted = [
|
| 684 |
+
f"{self.kg_processed_per_shift:,.0f}",
|
| 685 |
+
f"${self.labour_cost_per_shift:,.2f}",
|
| 686 |
+
f"${self.variable_cost_per_shift:,.2f}",
|
| 687 |
+
f"${self.overhead_cost_per_shift:,.2f}",
|
| 688 |
+
]
|
| 689 |
+
processing_data_dict = {
|
| 690 |
+
"Metric (Per Shift)": [
|
| 691 |
+
"Kilograms Extracted",
|
| 692 |
+
"Labour Cost",
|
| 693 |
+
"Variable Cost",
|
| 694 |
+
"Overhead",
|
| 695 |
+
],
|
| 696 |
+
"Value": processing_values_formatted,
|
| 697 |
+
}
|
| 698 |
+
self.processing_data_df = pd.DataFrame(processing_data_dict)
|
| 699 |
+
if hasattr(self, "processing_table"):
|
| 700 |
+
self.processing_table.value = self.processing_data_df
|
| 701 |
+
|
| 702 |
+
def _get_money_formatters(self):
|
| 703 |
+
return {
|
| 704 |
+
"$/kg Biomass": get_formatter("$%.02f"),
|
| 705 |
+
"$/kg Output": get_formatter("$%.02f"),
|
| 706 |
+
"Per Shift": get_formatter("$%.02f"),
|
| 707 |
+
"Per Day": get_formatter("$%.02f"),
|
| 708 |
+
"Per Week": get_formatter("$%.02f"),
|
| 709 |
+
}
|
| 710 |
+
|
| 711 |
+
def view(self):
|
| 712 |
+
input_col_max_width = 400
|
| 713 |
+
col1 = pn.Column(
|
| 714 |
+
"### Extraction",
|
| 715 |
+
self.kg_processed_per_hour_slider,
|
| 716 |
+
self.finished_product_yield_pct_slider,
|
| 717 |
+
sizing_mode="stretch_width",
|
| 718 |
+
max_width=input_col_max_width,
|
| 719 |
+
)
|
| 720 |
+
col2 = pn.Column(
|
| 721 |
+
pn.pane.Markdown("### Biomass parameters"),
|
| 722 |
+
self.bio_cbx_pct_slider,
|
| 723 |
+
self.bio_cost_slider,
|
| 724 |
+
sizing_mode="stretch_width",
|
| 725 |
+
max_width=input_col_max_width,
|
| 726 |
+
)
|
| 727 |
+
col3 = pn.Column(
|
| 728 |
+
pn.pane.Markdown("### Consumable rates"),
|
| 729 |
+
self.kwh_rate_slider,
|
| 730 |
+
self.water_cost_per_1000l_slider,
|
| 731 |
+
self.consumables_per_kg_bio_rate_slider,
|
| 732 |
+
sizing_mode="stretch_width",
|
| 733 |
+
max_width=input_col_max_width,
|
| 734 |
+
)
|
| 735 |
+
col4 = pn.Column(
|
| 736 |
+
pn.pane.Markdown("### Wholesale details"),
|
| 737 |
+
self.wholesale_cbx_price_slider,
|
| 738 |
+
self.wholesale_cbx_pct_slider,
|
| 739 |
+
sizing_mode="stretch_width",
|
| 740 |
+
max_width=input_col_max_width,
|
| 741 |
+
)
|
| 742 |
+
col5 = pn.Column(
|
| 743 |
+
pn.pane.Markdown("### Variable costs"),
|
| 744 |
+
self.kwh_per_kg_bio_slider,
|
| 745 |
+
self.water_liters_consumed_per_kg_bio_slider,
|
| 746 |
+
self.consumables_per_kg_output_slider,
|
| 747 |
+
sizing_mode="stretch_width",
|
| 748 |
+
max_width=input_col_max_width,
|
| 749 |
+
)
|
| 750 |
+
col6 = pn.Column(
|
| 751 |
+
pn.pane.Markdown("### Compliance"),
|
| 752 |
+
self.batch_test_cost_slider,
|
| 753 |
+
pn.pane.Markdown("### Overhead"),
|
| 754 |
+
self.fixed_overhead_per_week_slider,
|
| 755 |
+
sizing_mode="stretch_width",
|
| 756 |
+
max_width=input_col_max_width,
|
| 757 |
+
)
|
| 758 |
+
col8 = pn.Column(
|
| 759 |
+
pn.pane.Markdown("### Worker Details"),
|
| 760 |
+
self.workers_per_shift_slider,
|
| 761 |
+
self.worker_hourly_rate_slider,
|
| 762 |
+
self.managers_per_shift_slider,
|
| 763 |
+
self.manager_hourly_rate_slider,
|
| 764 |
+
sizing_mode="stretch_width",
|
| 765 |
+
max_width=input_col_max_width,
|
| 766 |
+
)
|
| 767 |
+
col9 = pn.Column(
|
| 768 |
+
pn.pane.Markdown("### Shift details"),
|
| 769 |
+
self.labour_hours_per_shift_slider,
|
| 770 |
+
self.processing_hours_per_shift_slider,
|
| 771 |
+
self.shifts_per_day_slider,
|
| 772 |
+
self.shifts_per_week_slider,
|
| 773 |
+
sizing_mode="stretch_width",
|
| 774 |
+
max_width=input_col_max_width,
|
| 775 |
+
)
|
| 776 |
+
|
| 777 |
+
input_grid = pn.FlexBox(
|
| 778 |
+
col1, col2, col3, col4, col5, col8, col9, col6, align_content="normal"
|
| 779 |
+
)
|
| 780 |
+
|
| 781 |
+
money_table_display = pn.Column(
|
| 782 |
+
pn.pane.Markdown("### Financial Summary", styles={"text-align": "center"}),
|
| 783 |
+
self.money_table,
|
| 784 |
+
sizing_mode="stretch_width",
|
| 785 |
+
max_width=700,
|
| 786 |
+
)
|
| 787 |
+
|
| 788 |
+
profit_table_display = pn.Column(
|
| 789 |
+
pn.pane.Markdown("### Profitability", styles={"text-align": "center"}),
|
| 790 |
+
self.profit_table,
|
| 791 |
+
sizing_mode="stretch_width",
|
| 792 |
+
max_width=input_col_max_width,
|
| 793 |
+
)
|
| 794 |
+
|
| 795 |
+
processing_table_display = pn.Column(
|
| 796 |
+
pn.pane.Markdown("### Processing Summary", styles={"text-align": "center"}),
|
| 797 |
+
self.processing_table,
|
| 798 |
+
sizing_mode="stretch_width",
|
| 799 |
+
max_width=input_col_max_width,
|
| 800 |
+
)
|
| 801 |
+
|
| 802 |
+
profit_weekly = pn.indicators.Number(
|
| 803 |
+
name="Weekly Profit",
|
| 804 |
+
value=self.net_rev_per_week,
|
| 805 |
+
format=f"${self.net_rev_per_week / 1000:.0f} k",
|
| 806 |
+
default_color="green",
|
| 807 |
+
align="center",
|
| 808 |
+
)
|
| 809 |
+
|
| 810 |
+
profit_pct = pn.indicators.Number(
|
| 811 |
+
name="Operating Profit",
|
| 812 |
+
value=self.operating_profit_pct,
|
| 813 |
+
format=f"{self.operating_profit_pct * 100.0:.2f}%",
|
| 814 |
+
default_color="green",
|
| 815 |
+
align="center",
|
| 816 |
+
)
|
| 817 |
+
|
| 818 |
+
table_grid = pn.FlexBox(
|
| 819 |
+
profit_weekly,
|
| 820 |
+
profit_pct,
|
| 821 |
+
processing_table_display,
|
| 822 |
+
profit_table_display,
|
| 823 |
+
money_table_display,
|
| 824 |
+
align_content="normal",
|
| 825 |
+
)
|
| 826 |
+
|
| 827 |
+
main_layout = pn.Column(
|
| 828 |
+
input_grid,
|
| 829 |
+
pn.layout.Divider(margin=(10, 0)),
|
| 830 |
+
table_grid,
|
| 831 |
+
styles={"margin": "0px 10px"},
|
| 832 |
+
)
|
| 833 |
+
|
| 834 |
+
return main_layout
|
| 835 |
+
|
| 836 |
+
|
| 837 |
+
estimator_app = CannabinoidEstimator()
|
| 838 |
+
# To run in a Panel server:
|
| 839 |
+
# pn.config.raw_css = custom_themes.get_base_css(custom_themes.DARK_THEME_VARS)
|
| 840 |
+
estimator_app.view().servable(title="CBx Revenue Estimator")
|
| 841 |
+
|
| 842 |
+
if __name__ == "__main__":
|
| 843 |
+
pn.serve(
|
| 844 |
+
estimator_app.view(),
|
| 845 |
+
title="CBx Revenue Estimator (Panel)",
|
| 846 |
+
show=True,
|
| 847 |
+
port=5007,
|
| 848 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|