Skip to content

Commit

Permalink
draft for pdf view
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha-tsepilova committed Dec 13, 2023
1 parent 2b323d4 commit aff7317
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions SynRD/papers/iverson22football.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Iverson22Football(Publication):
]

# FILENAME = "iverson22football"
PUBLICATION_FILE = "../../annotated_pdfs/high_school_football_annotated.pdf"

def __init__(self, dataframe=None):
super(Iverson22Football, self).__init__(dataframe=dataframe)
Expand Down
2 changes: 2 additions & 0 deletions SynRD/papers/lee2021ability.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class Lee2021Ability(Publication):
'W1PARENT'
]

PUBLICATION_FILE = "..\\..\\annotated_pdfs\\ability_self_concepts_annotated.pdf"

WEIGHTS = None

corr_df = None
Expand Down
1 change: 1 addition & 0 deletions SynRD/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Publication():

FILENAME = None

PUBLICATION_FILE = None
def __init__(self, dataframe=None, description=None):
if dataframe is not None:
self.dataframe = dataframe
Expand Down
14 changes: 14 additions & 0 deletions docs/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
</head>
<body>
<div id="heatmap"></div>
<object data="../../annotated_pdfs/who_gets_benefit_of_the_doubt_annotated.pdf#page=5" type="application/pdf" width="100%" height="500px">
<p>Unable to display PDF file. <a href="../../annotated_pdfs/who_gets_benefit_of_the_doubt_annotated.pdf#page=5">Download</a> instead.</p>
</object>

<script>
// Fetch the data
const JSON = 'formatted_data.json';
fetch('formatted_data.json')
.then(response => response.json())
.then(data => {
Expand Down Expand Up @@ -74,10 +78,20 @@
const config = {
responsive: true,
};
var myPlot = document.getElementById('heatmap');

// Generate the plot
Plotly.newPlot('heatmap', [trace], layout, config);
myPlot.on('plotly_click', function(data){
console.log(data);
})
});
// Plotly.d3.json(JSON, function (rows) {
// var myPlot = document.getElementById('heatmap');
// myPlot.on('plotly_click', function(data){
// console.log(data);
// })
// });
</script>
</body>
</html>
31 changes: 22 additions & 9 deletions docs/web/preprocess.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@
"cells": [
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"name": "stderr",
"output_type": "stream",
"text": [
"{'iverson22football': <class 'SynRD.papers.iverson22football.Iverson22Football'>, 'lee2021ability': <class 'SynRD.papers.lee2021ability.Lee2021Ability'>}\n",
"Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], dtype='int64')\n",
"Index([12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], dtype='int64')\n",
"{'data': [[0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.6799999999999998, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 0.6399999999999999, 0.5999999999999999, 0.5999999999999999, 0.6399999999999999, 1.0, 1.0, 1.0, 1.0, 1.0]], 'columns': ['iverson22football-0', 'iverson22football-1', 'iverson22football-2', 'iverson22football-3', 'iverson22football-4', 'iverson22football-5', 'iverson22football-6', 'lee2021ability-0', 'lee2021ability-1', 'lee2021ability-2', 'lee2021ability-3', 'lee2021ability-4'], 'index': ['privbayes - 0.37', 'privbayes - 1.0'], 'findings': [['The sample was, on average, 38 years old<br>at the Wave V assessment.', 'During the Wave V assessment, 307<br>(17.4%) men reported being diagnosed<br>with depression at some point in their<br>life, 275 (15.6%) being diagnosed with<br>an anxiety disorder or panic disorder at<br>some point in their life, 211 (12.0%)<br>having received psychological or<br>emotional counseling in the past 12<br>months, 125 (7.1%) reported seriously<br>thinking about suicide in the past year,<br>and 101 (5.8%) reported feeling<br>depressed in the previous week (i.e., “a<br>lot of the time” or “most of the time or<br>all of the time” over the past 7 days).', 'Examining responses the participants<br>gave during the Wave I assessment when<br>they were adolescents, 369 (20.9%)<br>reported playing (or intending to play)<br>football in high school and 952 (54.0%)<br>reported not intending to play football<br>in high school. Of note, 441<br>participants (25% of the sample) did not<br>answer this question and were excluded<br>from analyses pertaining to football<br>participation.', 'During Wave I, there were 174 boys<br>(9.9%) who reported undergoing<br>psychological counseling in the past<br>year while in high school. During the<br>Wave V interview, ~24 years later, those<br>individuals who underwent psychological<br>counseling during adolescence were much<br>more likely to report (i) a lifetime<br>history of depression [37.4 vs. 15.3%,<br>χ2 ((11)) = 53.17, p &lt; 0.001, OR=<br>3.31, 95% CI = 2.37-4.64],', '(ii) a lifetime history of an anxiety<br>disorder or panic disorder [31.0 vs.<br>14.9%, χ2 ((11)) = 41.12, p &lt; 0.001,<br>OR= 2.61, 95% CI = 1.94-3.50],', '(iii) having received psychological<br>counseling in the past 12 months [31.0<br>vs. 12.0%, χ2 ((11)) = 36.00, p &lt;<br>0.001, OR= 2.70, 95% CI = 1.98-3.67],', '(iv) suicidal ideation in the past year<br>[12.6 vs. 6.4%, χ2(1) = 9.24 , 95%CI =<br>1.29–3.44], , p = 0.002, OR = 2.11', 'As predicted, a negative correlation was<br>found between perceived low math teacher<br>support and 11thgrade math achievement<br>(r = -0.11).', \"Ability self-concepts and parental<br>supportin 9th grade were positively<br>correlated with students'11th grade<br>achievement (r = 0.30 and r = 0.12<br>respectively).\", 'A strong positive correlation was found<br>between9th and 11th grade math<br>achievement (r = 0.74).', \"perceived low math teacher support in<br>11th gradenegatively predicted students'<br>11th grade math achievement(B = -1.51, p<br>&lt; .001) while controlling for<br>students'demographics, 9th grade math<br>achievement score, and mathcourse.\", 'Second, as shown under Model 2, math<br>ability self-conceptspositively and<br>directly predicted 11th grade math<br>achievement(B = 2.51, p &lt; .001).'], ['The sample was, on average, 38 years old<br>at the Wave V assessment.', 'During the Wave V assessment, 307<br>(17.4%) men reported being diagnosed<br>with depression at some point in their<br>life, 275 (15.6%) being diagnosed with<br>an anxiety disorder or panic disorder at<br>some point in their life, 211 (12.0%)<br>having received psychological or<br>emotional counseling in the past 12<br>months, 125 (7.1%) reported seriously<br>thinking about suicide in the past year,<br>and 101 (5.8%) reported feeling<br>depressed in the previous week (i.e., “a<br>lot of the time” or “most of the time or<br>all of the time” over the past 7 days).', 'Examining responses the participants<br>gave during the Wave I assessment when<br>they were adolescents, 369 (20.9%)<br>reported playing (or intending to play)<br>football in high school and 952 (54.0%)<br>reported not intending to play football<br>in high school. Of note, 441<br>participants (25% of the sample) did not<br>answer this question and were excluded<br>from analyses pertaining to football<br>participation.', 'During Wave I, there were 174 boys<br>(9.9%) who reported undergoing<br>psychological counseling in the past<br>year while in high school. During the<br>Wave V interview, ~24 years later, those<br>individuals who underwent psychological<br>counseling during adolescence were much<br>more likely to report (i) a lifetime<br>history of depression [37.4 vs. 15.3%,<br>χ2 ((11)) = 53.17, p &lt; 0.001, OR=<br>3.31, 95% CI = 2.37-4.64],', '(ii) a lifetime history of an anxiety<br>disorder or panic disorder [31.0 vs.<br>14.9%, χ2 ((11)) = 41.12, p &lt; 0.001,<br>OR= 2.61, 95% CI = 1.94-3.50],', '(iii) having received psychological<br>counseling in the past 12 months [31.0<br>vs. 12.0%, χ2 ((11)) = 36.00, p &lt;<br>0.001, OR= 2.70, 95% CI = 1.98-3.67],', '(iv) suicidal ideation in the past year<br>[12.6 vs. 6.4%, χ2(1) = 9.24 , 95%CI =<br>1.29–3.44], , p = 0.002, OR = 2.11', 'As predicted, a negative correlation was<br>found between perceived low math teacher<br>support and 11thgrade math achievement<br>(r = -0.11).', \"Ability self-concepts and parental<br>supportin 9th grade were positively<br>correlated with students'11th grade<br>achievement (r = 0.30 and r = 0.12<br>respectively).\", 'A strong positive correlation was found<br>between9th and 11th grade math<br>achievement (r = 0.74).', \"perceived low math teacher support in<br>11th gradenegatively predicted students'<br>11th grade math achievement(B = -1.51, p<br>&lt; .001) while controlling for<br>students'demographics, 9th grade math<br>achievement score, and mathcourse.\", 'Second, as shown under Model 2, math<br>ability self-conceptspositively and<br>directly predicted 11th grade math<br>achievement(B = 2.51, p &lt; .001).']]}\n"
"c:\\Users\\l\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\pandas\\core\\computation\\expressions.py:20: UserWarning: Pandas requires version '2.7.3' or newer of 'numexpr' (version '2.7.1' currently installed).\n",
" from pandas.core.computation.check import NUMEXPR_INSTALLED\n"
]
},
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'SynRD'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Input \u001b[1;32mIn [1]\u001b[0m, in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mjson\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mSynRD\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mpapers\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Iverson22Football, Lee2021Ability\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mtextwrap\u001b[39;00m\n",
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'SynRD'"
]
}
],
Expand Down Expand Up @@ -44,16 +53,19 @@
" wrapped_hovertext = [\"<br>\".join(textwrap.wrap(text,width=width)) for text in hovertext]\n",
" return wrapped_hovertext\n",
"\n",
"paper_name_to_pdfs = {}\n",
"for (synthesizer, epsilon), group in grouped:\n",
" # sort based on 'paper' and 'finding_number'\n",
" group = group.sort_values(['paper', 'finding_number'])\n",
" \n",
" if not columns:\n",
" columns = list(group['paper'] + '-' + group['finding_number'].astype(str))\n",
" findings_in_group = []\n",
"\n",
" for i in group.index:\n",
" paper_name = group['paper'][i]\n",
" paper_class=names_to_papers[paper_name]\n",
" paper_name_to_pdfs[paper_name] = paper_class.PUBLICATION_FILE\n",
" finding = paper_class(silly_df).FINDINGS[group['finding_number'][i]].text.replace('\\n', ' ').replace(2*' ',\"\")\n",
" findings_in_group.append(finding)\n",
"\n",
Expand All @@ -65,15 +77,16 @@
" 'data': data,\n",
" 'columns': columns,\n",
" 'index': index,\n",
" 'findings': findings\n",
" 'findings': findings,\n",
" 'pdfs' :paper_name_to_pdfs\n",
"}\n",
"with open('formatted_data.json', 'w') as f:\n",
" json.dump(result, f)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -327,7 +340,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.8.5"
},
"orig_nbformat": 4,
"vscode": {
Expand Down

0 comments on commit aff7317

Please sign in to comment.