API Reference
reddwarf.implementations.base
reddwarf.implementations.base.run_pipeline(votes, reducer='pca', reducer_kwargs={}, clusterer='kmeans', clusterer_kwargs={}, mod_out_statement_ids=[], meta_statement_ids=[], min_user_vote_threshold=7, keep_participant_ids=[], init_centers=None, max_group_count=5, force_group_count=None, random_state=None, pick_max=5, confidence=0.9, consensus_mode='standard', candidate_group_counts=None)
An essentially feature-complete implementation of the Polis clustering algorithm.
Still missing
- base-cluster calculations (so can't match output of conversations larger than 100 participants),
- k-smoothing, which holds back k-value (group count) until re-calculated 3 consecutive times,
- some advanced participant filtering that involves past state (you can use keep_participant_ids to mimic manually).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/implementations/base.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 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 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 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 | |
reddwarf.implementations.agora
reddwarf.implementations.agora.run_pipeline(fdr_rate=0.1, **kwargs)
Agora clustering pipeline. Runs the base pipeline and adds ranked representative/consensus statements with Benjamini-Hochberg selection.
Accepts all the same arguments as base.run_pipeline(), plus:
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/implementations/agora.py
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 | |
reddwarf.implementations.agora.AgoraClusteringResult
dataclass
| Attributes: |
|
|---|
Source code in reddwarf/implementations/agora.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
reddwarf.implementations.agora.compute_effective_agreement_gac(grouped_stats_df, statement_ids, n_groups)
Compute GAC using effective agreement: prod(pa * (1-pd))^(1/n_groups).
Unlike the Polis formula (raw pa product), this penalizes groups that are genuinely divided (high agree AND high disagree) by discounting each group's agreement by its disagreement.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/implementations/agora.py
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 | |
reddwarf.implementations.polis
reddwarf.implementations.polis.run_pipeline(votes, reducer='pca', reducer_kwargs=None, clusterer='kmeans', clusterer_kwargs=None, mod_out_statement_ids=None, meta_statement_ids=None, min_user_vote_threshold=7, keep_participant_ids=None, init_centers=None, max_group_count=5, force_group_count=None, random_state=None, pick_max=5, confidence=0.9, consensus_mode='legacy', candidate_group_counts=None)
Source code in reddwarf/implementations/polis.py
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 | |
reddwarf.sklearn
Various custom Scikit-Learn estimators to mimick aspects of Polis, suitable for use in Scikit-Learn workflows, pipelines, and APIs.
reddwarf.sklearn.cluster.PolisKMeans
Bases: KMeans
A modified version of scikit-learn's KMeans that allows partial initialization with user-supplied cluster centers and custom fallback strategies.
This subclass extends sklearn.cluster.KMeans with additional features
around centroid initialization. Outside the behavior documented, it retains
all other parameters and behavior from the base KMeans implementation.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
See Also
sklearn.cluster.KMeans : Original implementation with full parameter list.
Source code in reddwarf/sklearn/cluster.py
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 | |
reddwarf.sklearn.cluster.PolisKMeansDownsampler
Bases: BaseEstimator, TransformerMixin
A transformer that fits PolisKMeans and returns cluster centers as downsampled data.
This supports mimicking "base clusters" from the Polis platform and enables use in sklearn pipelines where intermediate steps implement both fit and transform.
Parameters
n_clusters : int, default=100 Number of clusters to form random_state : int, RandomState instance or None, default=None Random state for reproducible results init : {'k-means++', 'random', 'polis'}, default='k-means++' Initialization strategy init_centers : array-like of shape (n_clusters, n_features), optional Initial cluster centers
Source code in reddwarf/sklearn/cluster.py
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 | |
reddwarf.sklearn.model_selection.GridSearchNonCV
Bases: GridSearchCV
sklearn.model_selection.GridSearchCV, but modified to score against the
full dataset (ie. not cross-validated).
Normally, GridSearchCV splits up the X data and scores each "fold" of data.
This is identical, but we automatically use the full dataset in each fold.
Source code in reddwarf/sklearn/model_selection.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
reddwarf.sklearn.transformers.SparsityAwareScaler
Bases: BaseEstimator, TransformerMixin
Scale projected points (participant or statements) based on sparsity of vote matrix, to account for any small number of votes by a participant and prevent those participants from bunching up in the center.
| Attributes: |
|
|---|
Source code in reddwarf/sklearn/transformers.py
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 | |
reddwarf.utils.matrix
reddwarf.utils.matrix.generate_raw_matrix(votes, cutoff=None)
Generates a raw vote matrix from a list of vote records.
See filter_votes method for details of cutoff arg.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/matrix.py
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 | |
reddwarf.utils.matrix.simple_filter_matrix(vote_matrix, mod_out_statement_ids=[])
The simple filter on the vote_matrix that is used by Polis prior to running PCA.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/matrix.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
reddwarf.utils.matrix.get_clusterable_participant_ids(vote_matrix, vote_threshold)
Find participant IDs that meet a vote threshold in a vote_matrix.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/matrix.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
reddwarf.utils.reducer
reddwarf.utils.reducer.base.run_reducer(vote_matrix, reducer='pca', n_components=2, **reducer_kwargs)
Process a prepared vote matrix to be imputed and return participant and (optionally) statement data, projected into reduced n-dimensional space.
The vote matrix should not yet be imputed, as this will happen within the method.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/reducer/base.py
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 | |
reddwarf.utils.reducer.base.get_reducer(reducer='pca', n_components=2, random_state=None, **reducer_kwargs)
Source code in reddwarf/utils/reducer/base.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
reddwarf.utils.clusterer
reddwarf.utils.clusterer.base.run_clusterer(X_participants_clusterable, clusterer='kmeans', force_group_count=None, max_group_count=5, init_centers=None, random_state=None, **clusterer_kwargs)
Source code in reddwarf/utils/clusterer/base.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
reddwarf.utils.clusterer.kmeans.find_best_kmeans(X_to_cluster, k_bounds=[2, 5], init='k-means++', init_centers=None, random_state=None)
Use silhouette scores to find the best number of clusters k to assume to fit the data.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/clusterer/kmeans.py
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 | |
reddwarf.utils.consensus
reddwarf.utils.consensus.select_consensus_statements(vote_matrix, mod_out_statement_ids=[], pick_max=5, prob_threshold=0.5, confidence=0.9)
Select consensus statements from a given vote matrix.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/consensus.py
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 | |
reddwarf.utils.consensus.rank_consensus_statements(vote_matrix, mod_out_statement_ids=[], fdr_rate=0.1)
Ranks ALL statements by consensus strength and marks selections via Benjamini-Hochberg.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/consensus.py
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 | |
reddwarf.utils.stats
reddwarf.utils.stats.select_representative_statements(grouped_stats_df, mod_out_statement_ids=[], pick_max=5, confidence=0.9)
Selects statistically representative statements from each group cluster.
This is expected to match the Polis outputs when all defaults are set.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/stats.py
679 680 681 682 683 684 685 686 687 688 689 690 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 722 723 724 725 726 727 728 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 760 761 762 763 764 | |
reddwarf.utils.stats.rank_representative_statements(grouped_stats_df, mod_out_statement_ids=[], fdr_rate=0.1)
Ranks ALL statements per group by effect size and marks selections via Benjamini-Hochberg.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/stats.py
767 768 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 797 798 799 800 801 802 803 804 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 850 851 852 853 854 855 856 857 858 859 860 | |
reddwarf.utils.stats.apply_bh_with_vote_filter(p_values, has_votes, fdr_rate)
Apply BH selection only to testable statements (those with votes).
Statements without votes get selected=False and adjusted_p_value=1.0. This avoids inflating the hypothesis count with noise from Laplace smoothing.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/stats.py
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 | |
reddwarf.utils.stats.calculate_comment_statistics(vote_matrix, cluster_labels=None, pseudo_count=1, consensus_mode='standard')
Calculates comparative statement statistics across all votes and groups, using only efficient numpy operations.
Note: when no cluster_labels are supplied, we internally apply the group 0 to each row,
and calculated values can be accessed in the first group index.
The representativeness metric is defined as: R_v(g,c) = P_v(g,c) / P_v(~g,c)
Where: - P_v(g,c) is probability of vote v on comment c in group g - P_v(~g,c) is probability of vote v on comment c in all groups except g
And: - N(g,c) is the total number of non-missing votes on comment c in group g - N_v(g,c) is the total number of vote v on comment c in group g
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/stats.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 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 | |
reddwarf.utils.stats.calculate_comment_statistics_dataframes(vote_matrix, cluster_labels=None, pseudo_count=1, consensus_mode='standard')
Calculates comparative statement statistics across all votes and groups, generating dataframes.
This returns both group-specific statistics, and also overall stats (group-aware consensus).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/stats.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 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 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
reddwarf.utils
(These are in the process of being either moved or deprecated.)
reddwarf.utils.filter_votes(votes, cutoff=None)
Filters a list of votes.
If a cutoff is provided, votes are filtered based on either:
- An
intrepresenting unix timestamp (ms), keeping only votes before or at that time.- Any int above 13_000_000_000 is considered a timestamp.
- Any other positive or negative
intis considered an index, reflecting where to trim the time-sorted vote list.- positive: filters in votes that many indices from start
- negative: filters out votes that many indices from end
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/matrix.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
reddwarf.utils.filter_matrix(vote_matrix, min_user_vote_threshold=7, active_statement_ids=[], keep_participant_ids=[], unvoted_filter_type='drop')
Generates a filtered vote matrix from a raw matrix and filter config.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/utils/matrix.py
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 | |
reddwarf.utils.get_unvoted_statement_ids(vote_matrix)
A method intended to be piped into a VoteMatrix DataFrame, returning list of unvoted statement IDs.
See: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.pipe.html
| Parameters: |
|
|---|
| Returns: |
|
|---|
Example:
unused_statement_ids = vote_matrix.pipe(get_unvoted_statement_ids)
Source code in reddwarf/utils/matrix.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
reddwarf.data_loader
reddwarf.data_loader.Loader
A comprehensive data loader for Polis conversation data.
The Loader class provides a unified interface for loading Polis conversation data from multiple sources including API endpoints, CSV exports, and local JSON files. It handles data validation, caching, rate limiting, and export functionality.
The class automatically determines the appropriate loading strategy based on the provided parameters and can export data in both JSON and CSV formats compatible with the Polis platform.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Examples:
Load from API using conversation ID:
>>> loader = Loader(conversation_id="12345")
Load from CSV export using report ID:
>>> loader = Loader(report_id="r67890", data_source="csv_export")
Load from local files:
>>> loader = Loader(filepaths=["votes.json", "comments.json", "math-pca2.json"])
Load and export to directory:
>>> loader = Loader(conversation_id="12345", output_dir="./exported_data")
Source code in reddwarf/data_loader.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 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 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 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 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 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
dump_data(output_dir)
Export loaded data to JSON files in the specified directory.
| Parameters: |
|
|---|
Note
This method is deprecated. Use export_data() instead.
Source code in reddwarf/data_loader.py
123 124 125 126 127 128 129 130 131 132 133 | |
export_data(output_dir, format)
A simple wrapper around Exporter.export
Source code in reddwarf/data_loader.py
111 112 113 114 115 116 117 118 119 120 | |
fetch_pid(xid)
Fetch internal participant ID (pid) for a given external ID (xid).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/data_loader.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
fetch_xid_to_pid_mappings(xids=[])
Create mapping dictionary from external IDs to internal participant IDs.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/data_loader.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
filter_duplicate_votes(keep='recent')
Remove duplicate votes from the same participant on the same statement.
| Parameters: |
|
|---|
The filtered duplicate votes are stored in self.skipped_dup_votes for reference.
| Raises: |
|
|---|
Source code in reddwarf/data_loader.py
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 315 316 317 318 319 320 | |
fix_participant_vote_sign()
Correct vote sign inversion in API data.
The Polis API returns votes with inverted signs compared to the expected format (e.g., agree votes come as -1 instead of 1). This method fixes the inversion by negating all vote values.
Source code in reddwarf/data_loader.py
517 518 519 520 521 522 523 524 525 526 527 | |
get_polis_export_directory_url(report_id)
Generate the CSV export directory URL for a given report ID.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/data_loader.py
183 184 185 186 187 188 189 190 191 192 193 | |
init_http_client()
Initialize HTTP session with rate limiting, caching, and Cloudflare bypass.
Sets up a requests session with: - Rate limiting (5 requests per second) - Optional SQLite-based response caching (1 hour expiration) - Cloudflare bypass adapter for the Polis instance - Random user agent headers
Source code in reddwarf/data_loader.py
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 | |
load_api_data()
Load complete dataset from Polis API endpoints.
Loads data in the following order: 1. Report data (if report_id provided) to get conversation_id 2. Conversation metadata 3. Comments/statements data 4. Mathematical analysis data (PCA, clustering) 5. Individual participant votes (up to participant count from math data)
Automatically handles vote sign correction for API data and resolves any conflicts between report_id and conversation_id parameters.
| Raises: |
|
|---|
Source code in reddwarf/data_loader.py
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 | |
load_api_data_comments()
Load statement/comment data from the Polis API.
Fetches all statements with moderation status and voting patterns included in the response.
Source code in reddwarf/data_loader.py
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
load_api_data_conversation()
Load conversation metadata from the Polis API.
Fetches conversation details including topic, description, and settings using the conversation_id.
Source code in reddwarf/data_loader.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
load_api_data_math()
Load mathematical analysis data from the Polis API.
Fetches PCA projections, clustering results, and group statistics from the math/pca2 endpoint.
Source code in reddwarf/data_loader.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
load_api_data_report()
Load report metadata from the Polis API.
Uses the report_id to fetch report information and extract the associated conversation_id for subsequent API calls.
Source code in reddwarf/data_loader.py
452 453 454 455 456 457 458 459 460 461 462 463 464 | |
load_api_data_votes(last_participant_id=None)
Load individual participant votes from the Polis API.
| Parameters: |
|
|---|
Iterates through all participant IDs from 0 to last_participant_id and fetches their vote records. Automatically applies vote sign correction.
Source code in reddwarf/data_loader.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
load_file_data()
Load data from local JSON files specified in self.filepaths.
Automatically detects file types based on filename patterns: - votes.json: Vote records - comments.json: Statement/comment data - conversation.json: Conversation metadata - math-pca2.json: Mathematical analysis results
| Raises: |
|
|---|
Source code in reddwarf/data_loader.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
load_file_data_comments(file=None)
Load statement/comment data from a local JSON file.
| Parameters: |
|
|---|
Source code in reddwarf/data_loader.py
378 379 380 381 382 383 384 385 386 387 388 389 | |
load_file_data_conversation(file=None)
Load conversation metadata from a local JSON file.
| Parameters: |
|
|---|
Source code in reddwarf/data_loader.py
391 392 393 394 395 396 397 398 399 400 401 | |
load_file_data_math(file=None)
Load mathematical analysis data from a local JSON file.
| Parameters: |
|
|---|
Source code in reddwarf/data_loader.py
403 404 405 406 407 408 409 410 411 412 413 | |
load_file_data_votes(file=None)
Load vote data from a local JSON file.
| Parameters: |
|
|---|
Source code in reddwarf/data_loader.py
365 366 367 368 369 370 371 372 373 374 375 376 | |
load_remote_export_data()
Load data from remote CSV export endpoints.
Downloads and processes CSV files from Polis export directory, including: - comments.csv: Statement data - votes.csv: Vote records
Handles missing is_meta field by falling back to API data when necessary. Automatically filters duplicate votes, keeping the most recent.
| Raises: |
|
|---|
Source code in reddwarf/data_loader.py
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 | |
load_remote_export_data_comments(directory_url)
Load statement/comment data from remote CSV export.
| Parameters: |
|
|---|
Source code in reddwarf/data_loader.py
258 259 260 261 262 263 264 265 266 267 268 269 270 | |
load_remote_export_data_votes(directory_url)
Load vote data from remote CSV export.
| Parameters: |
|
|---|
Source code in reddwarf/data_loader.py
272 273 274 275 276 277 278 279 280 281 282 283 284 | |
populate_polis_ids()
Normalize and populate Polis ID fields from the provided identifiers.
This method handles the logic for determining conversation_id and report_id from the generic polis_id parameter. (Report IDs start with 'r', while conversation IDs start with a number.)
Source code in reddwarf/data_loader.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
reddwarf.data_presenter
reddwarf.data_presenter.generate_figure(coord_data, coord_labels=None, cluster_labels=None, flip_x=False, flip_y=False)
Generates a matplotlib scatterplot with optional bounded clusters.
The plot is drawn from a dataframe of xy values, each point labelled by index participant_id.
When a list of cluster labels are supplied (corresponding to each row), concave hulls are drawn around them.
Signs of PCA projection coordinates are arbitrary, and can flip without meaning. Inverting axes can help compare results with Polis platform visualizations.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in reddwarf/data_presenter.py
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 | |
reddwarf.data_presenter.generate_figure_polis(result, show_guesses=False, flip_x=True, flip_y=False, show_pids=True)
Generate a Polis-style visualization from clustering results.
| Parameters: |
|
|---|
Source code in reddwarf/data_presenter.py
22 23 24 25 26 27 28 29 30 31 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 | |
Types
reddwarf.implementations.base.AnalysisSuccess
dataclass
Bases: Generic[T]
Source code in reddwarf/implementations/base.py
41 42 43 44 | |
reddwarf.implementations.base.AnalysisInsufficientData
dataclass
Source code in reddwarf/implementations/base.py
47 48 49 50 | |
reddwarf.implementations.base.InsufficientDataReason
Bases: str, Enum
Source code in reddwarf/implementations/base.py
34 35 36 37 38 | |
reddwarf.implementations.base.PolisClusteringResult
dataclass
| Attributes: |
|
|---|
Source code in reddwarf/implementations/base.py
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 | |
reddwarf.implementations.base.KMeansCandidatesResult
dataclass
Bases: Generic[T]
Source code in reddwarf/implementations/base.py
80 81 82 83 | |
reddwarf.implementations.base.KMeansCandidateSuccess
dataclass
Bases: Generic[T]
Source code in reddwarf/implementations/base.py
65 66 67 68 69 70 | |
reddwarf.implementations.base.KMeansCandidateInsufficientData
dataclass
Source code in reddwarf/implementations/base.py
73 74 75 76 77 | |
reddwarf.types.agora.RankedRepnessStatement
dataclass
Source code in reddwarf/types/agora.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
reddwarf.types.agora.RankedConsensusStatement
dataclass
Source code in reddwarf/types/agora.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
reddwarf.types.agora.RankedConsensusResult
dataclass
Source code in reddwarf/types/agora.py
45 46 47 48 | |