Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
eireland committed Feb 16, 2024
2 parents f733b8e + fdd2ef8 commit 17fe88d
Show file tree
Hide file tree
Showing 13 changed files with 52,695 additions and 17 deletions.
9 changes: 6 additions & 3 deletions Importer/modules/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@
"DG.plugin.Choosy.title": "Choosy",
"DG.plugin.Choosy.description": "Organize and simplify datasets with many attributes.",
"DG.plugin.Transformers.title": "Transformers",
"DG.plugin.Transformers.description": "Transform datasets with a collection of powerful tools."
"DG.plugin.Transformers.description": "Transform datasets with a collection of powerful tools.",
"DG.plugin.Sampler.tab.devices": "Model",
"DG.plugin.Sampler.tab.measures": "Measures"
},
"de": {
"DG.plugin.Importer.title": "CSV importieren",
Expand Down Expand Up @@ -766,7 +768,7 @@
"DG.plugin.StoryBuilder.emptyMoment.createAlt": "yeni anlatı oluştur",
"DG.plugin.StoryBuilder.emptyMoment.createTitle": "Yeni bir anlatı oluşturmak için tıklayınız",
"DG.plugin.StoryBuilder.buttons.helpAlt": "yardım al",
"DG.plugin.StoryBuilder.buttons.helpTitle": "Anlatı Oluşturucu kullanımına yönelik yardı al",
"DG.plugin.StoryBuilder.buttons.helpTitle": "Anlatı Oluşturucu kullanımına yönelik yardım al",
"DG.plugin.StoryBuilder.buttons.autoSaveTitleAuto": "Mevcut durumda anlatılarda yapılan değişiklikler otomatik olarak kaydedilecektir. Anlatıları kaydetme ya da silme seçeneklerini görmek için tıklayınız.",
"DG.plugin.StoryBuilder.buttons.autoSaveTitleManual": "Mevcut durumda anlatılarda yapılan değişikliklerin kaydedilmesi veya silinmesi istenecektir. Anlatılardaki değişiklikleri sormaksızın otomatik olarak kaydetmek için tıklayınız.",
"DG.plugin.StoryBuilder.momentComponent.deleteAlt": "Bu anlatıyı sil",
Expand Down Expand Up @@ -897,6 +899,7 @@
"DG.plugin.Choosy.title": "Veri indirgeyici",
"DG.plugin.Choosy.description": "Bu eklentide çok özellikli veri setleri organize edilebilir ve veriler sadeleştirilebilir.",
"DG.plugin.Transformers.title": "Dönüştürücüler",
"DG.plugin.Transformers.description": "Bu eklentide sunulan birtakım araçlar yardımıyla veri setlerinde dönüşümler yapılabilir."
"DG.plugin.Transformers.description": "Bu eklentide sunulan birtakım araçlar yardımıyla veri setlerinde dönüşümler yapılabilir.",
"DG.plugin.Sampler.tab.measures": "Ölçümler"
}
}
12 changes: 7 additions & 5 deletions TP-Sampler/src/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@
"DG.plugin.Scrambler.sMeasureDatasetPrefix": "measures_from_",
"DG.plugin.Sampler.title": "Sampler",
"DG.plugin.Sampler.description": "Create random datasets from scratch or existing datasets.",
"DG.plugin.Sampler.tab.devices": "Model",
"DG.plugin.Sampler.tab.measures": "Measures",
"DG.plugin.Sampler.tab.sampler": "Sampler",
"DG.plugin.Sampler.tab.options": "Options",
"DG.plugin.Sampler.tab.about": "About",
"DG.plugin.Sampler.top-bar.run": "START",
Expand Down Expand Up @@ -195,7 +194,9 @@
"DG.plugin.Choosy.title": "Choosy",
"DG.plugin.Choosy.description": "Organize and simplify datasets with many attributes.",
"DG.plugin.Transformers.title": "Transformers",
"DG.plugin.Transformers.description": "Transform datasets with a collection of powerful tools."
"DG.plugin.Transformers.description": "Transform datasets with a collection of powerful tools.",
"DG.plugin.Sampler.tab.devices": "Model",
"DG.plugin.Sampler.tab.measures": "Measures"
},
"de": {
"DG.plugin.Importer.title": "CSV importieren",
Expand Down Expand Up @@ -767,7 +768,7 @@
"DG.plugin.StoryBuilder.emptyMoment.createAlt": "yeni anlatı oluştur",
"DG.plugin.StoryBuilder.emptyMoment.createTitle": "Yeni bir anlatı oluşturmak için tıklayınız",
"DG.plugin.StoryBuilder.buttons.helpAlt": "yardım al",
"DG.plugin.StoryBuilder.buttons.helpTitle": "Anlatı Oluşturucu kullanımına yönelik yardı al",
"DG.plugin.StoryBuilder.buttons.helpTitle": "Anlatı Oluşturucu kullanımına yönelik yardım al",
"DG.plugin.StoryBuilder.buttons.autoSaveTitleAuto": "Mevcut durumda anlatılarda yapılan değişiklikler otomatik olarak kaydedilecektir. Anlatıları kaydetme ya da silme seçeneklerini görmek için tıklayınız.",
"DG.plugin.StoryBuilder.buttons.autoSaveTitleManual": "Mevcut durumda anlatılarda yapılan değişikliklerin kaydedilmesi veya silinmesi istenecektir. Anlatılardaki değişiklikleri sormaksızın otomatik olarak kaydetmek için tıklayınız.",
"DG.plugin.StoryBuilder.momentComponent.deleteAlt": "Bu anlatıyı sil",
Expand Down Expand Up @@ -898,6 +899,7 @@
"DG.plugin.Choosy.title": "Veri indirgeyici",
"DG.plugin.Choosy.description": "Bu eklentide çok özellikli veri setleri organize edilebilir ve veriler sadeleştirilebilir.",
"DG.plugin.Transformers.title": "Dönüştürücüler",
"DG.plugin.Transformers.description": "Bu eklentide sunulan birtakım araçlar yardımıyla veri setlerinde dönüşümler yapılabilir."
"DG.plugin.Transformers.description": "Bu eklentide sunulan birtakım araçlar yardımıyla veri setlerinde dönüşümler yapılabilir.",
"DG.plugin.Sampler.tab.measures": "Ölçümler"
}
}
41 changes: 41 additions & 0 deletions data-science-worlds/nhanes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Instructions for updating data to query from NHANES.
1. Download data from [NHANES](https://wwwn.cdc.gov/nchs/nhanes/default.aspx). These files are in XPT format (SAS files).
a. Current datasets include:
* Demographics (demo)
* Standard Biochemistry Profile (biopro)
* Body Measures (bmx)
* Blood Pressure - Oscillometric Measurement (bp)
2. Convert the XPT files to MySQL database.
a. Install MySQL from [here](https://dev.mysql.com/downloads/mysql/). Instructions are [here](https://dev.mysql.com/doc/refman/8.0/en/macos-installation-pkg.html)
a. Install Python libraries pandas and sqlalchemy.
`pip3 install pandas sqlalchemy`
b. Run `create_nhanes_db.py` from root directory of nhanes project. This will create a database in the `usr/local/mysql` folder.
`python3 create_nhanes_db.py`
3. Install Sequel Ace using homebrew. This is just a GUI for MySQL, but creates the sql file that is similar to the one Sequel Pro generated.
`brew install --cask sequel-ace`
4. Run Sequel Ace and select the `nhanes` database from the dropdown at the top of the window, or from the menu Database > Go to Database
5. Export the tables.
a. From the menu Files > Export. In the dialog box, check all the checkboxes for the tables you would like to export. Each dataset is a table in the database. You can specify where to export the file to. For this repo, export the file to `codap-data-interactives/data-science-worlds/sql data`
6. Copy the `decoder` table from the previous `.sql` file. This will have most of the variables you need from the tables. You may have edit, add, delete variables depending on what data is available for the year(s) you selected.
7. copy the `varlist` table from the previous `.sql` file. This will have most of the variables you need from the tables. You may have edit, add, delete variables depending on what data is available for the year(s) you selected.

**To test local MySQL database**
1. Download and install [MAMP](https://www.mamp.info/en/mamp/mac/)
2. Make a folder named `cred` in `/Applications/MAMP/`. Make a copy of the `nhanes` folder and put the copy in the `cred` folder. Make a copy of the `common` folder in the `codap-data-interactive/data-science-worlds` folder and put the copy in the `cred` folder.
3. Move the `nhanesCred.php` in the `nhanes` folder out to the `cred` folder.
4. Launch MAMP. You may have to change your document root to `Applications > MAMP > cred`. This is because of the existing paths require us to put the `nhanes` folder in the `cred` folder.
5. Click on the Start button in MAMP. This should start up a local server that has MySQL in `localhost:8888`.
6. In a browser page, navigate to `http://localhost:8888/phpMyAdmin5/index.php`. This should bring up a GUI for accessing your database in `php`.
7. In phpAdmin, click on Import button. This brings up a dialog that will allow you to import the sql file. In the dialog, select the sql file in the `File To Import` section. Click on Import button at the bottom of the page. Once imported, you should see the nhanes database list on the left side, with the tables listed under the database name.
8. Navigating to `http://localhost:8888/nhanes/nhanes.php?c=getCases&tables=biochem&atts=*&joins=SEQN&n=15`, you should see a page full data. Note that navigating to `http://localhost:8888/nhanes/nhanes.php`, you will see `"{ Unhandled command : }"`.

**Load plugin in CODAP**
1. Start a local instance of CODAP.
2. Navigate to `http://localhost:4020/dg?di=http://localhost:8888/nhanes/nhanes.html`. You should see the plugin in CODAP.

**Upload data to CODAP server**
To use the new data in the nhanes plugin, the existing data in the database in the CODAP server needs to be replaced with the new data.
1. Upload the new sql file into the CODAP server. Currently, this should be stored in `var/www/html/data-science-worlds/nhanes/sql data`.
2. Back up the old database.
3. Drop the old database.
4. Create a new database called `nhanesdb`, and populate it with the data from you new sql file.
45 changes: 45 additions & 0 deletions data-science-worlds/nhanes/create_nhanes_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

import pandas as pd
from sqlalchemy import create_engine, text

user = 'root' # Enter your MySQL username here
pw = '' # Enter your MySQL password here

# Database configuration
db_config = {
'user': user,
'password': pw,
'host': 'localhost',
'port': '3306',
'database': 'nhanes'
}


# Function to create a database engine and ensure the database exists
def create_db_engine(db_config):
user = db_config['user']
password = db_config['password']
host = db_config['host']
port = db_config['port']
database = db_config['database']
# Connect without specifying a database to issue the CREATE DATABASE command
engine_without_db = create_engine(f'mysql+mysqlconnector://{user}:{password}@{host}:{port}/')
with engine_without_db.connect() as conn:
conn.execute(text(f"CREATE DATABASE IF NOT EXISTS {database}"))
# Return an engine connected to the specified database
engine_with_db = create_engine(f'mysql+mysqlconnector://{user}:{password}@{host}:{port}/{database}')
return engine_with_db

# Create the engine and ensure the database exists
engine = create_db_engine(db_config)

# List of XPT files
xpt_files = ['./xpt_data/P_BIOPRO.XPT', './xpt_data/P_BMX.XPT', './xpt_data/P_BPXO.XPT', './xpt_data/P_DEMO.XPT'] # Add more file paths as needed

# Process each XPT file to create a table in the database
for file_path in xpt_files:
df = pd.read_sas(file_path)
# Derive table name from file name (adjust as needed)
table_name = file_path.split('/')[-1].split('.')[0]
df.to_sql(table_name, con=engine, if_exists='replace', index=False)
print(f"Data from {file_path} inserted into table {table_name} in database {db_config['database']}.")
4 changes: 2 additions & 2 deletions data-science-worlds/nhanes/nhanes.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ nhanes.constants = {

kBasePhpURL: {
concord: 'https://codap.concord.org/data-science-worlds/nhanes/nhanes.php',
local: "http://localhost:8888/plugins/nhanes/nhanes.php",
local: "http://localhost:8888/nhanes/nhanes.php",
xyz: "https://codap.xyz/plugins/nhanes/nhanes.php",
eeps: "https://www.eeps.com/codap/nhanes/nhanes.php"
}
};
};
7 changes: 4 additions & 3 deletions data-science-worlds/nhanes/nhanes.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<body>

<div id="pluginHeader">
<h1>2003 NHANES Data Portal</h1>
<h1>2017-2020 Pre-Pandemic NHANES Data Portal</h1>
<label for="sampleSizeInput">How many people? </label>
<input id="sampleSizeInput" type="number" value="10" min="1" max="1000" onchange="nhanes.ui.updateWholeUI()">
<button id="getCasesButton" onclick="nhanes.userActions.pressGetCasesButton()">get people</button>
Expand All @@ -88,7 +88,7 @@ <h1>2003 NHANES Data Portal</h1>
<div id="summary">
<div id="sampleSummaryDiv"></div>
<p>Click the <b>get people</b> button to obtain a table with data from a random sample of Americans of all ages from
the 2003 National Health and Nutrition Examination Survey
the 2017-2020 Pre-Pandemic National Health and Nutrition Examination Survey
(<a href="https://www.cdc.gov/nchs/nhanes/index.htm" target="_blank">NHANES</a>).</a> For many more variables, click on the <b>options</b> tab. </p>
</div>

Expand Down Expand Up @@ -137,11 +137,12 @@ <h1>2003 NHANES Data Portal</h1>
in several ways, including informing policies leading to the removal of lead from U.S. gasoline, creating pediatric growth
charts, and estimating baseline standards for cholesterol, blood pressure, and Hepatitis C.
</p>
<p>The NHANES program suspended field operations in March 2020 due to the coronavirus disease 2019 (COVID-19) pandemic. As a result, data collection for the NHANES 2019-2020 cycle was not completed and the collected data are not nationally representative. Therefore, data collected from 2019 to March 2020 were combined with data from the NHANES 2017-2018 cycle to form a nationally representative sample of NHANES 2017-March 2020 pre-pandemic data.</p>
</div>


</div>


</body>
</html>
</html>
4 changes: 2 additions & 2 deletions data-science-worlds/nhanes/nhanes.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let nhanes = {
{number : 2, name : "bmx", open : false, title : "Body measurements"},
{number : 3, name : "bp", open : false, title : "Blood pressure"},
{number : 4, name : "biochem", open : false, title : "Biochemistry (bloodwork)"},
{number : 5, name : "sexactivity", open : false, title : "Sexual behavior (questionnaire)"}
// {number : 5, name : "sexactivity", open : false, title : "Sexual behavior (questionnaire)"}
],

placeOfBirth: {
Expand Down Expand Up @@ -303,4 +303,4 @@ placeOfBirth: {
554: "Other US Island Areas, Oceania, Not Specified, or at Sea",
555: "Other US Island Areas, Oceania, Not Specified, or at Sea"
}
};
};
4 changes: 2 additions & 2 deletions data-science-worlds/nhanes/nhanes.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ nhanes.ui = {
out = "<p>When you press the button, you will get "
+ (tSampleSize == 1 ? "one random American" : "a random sample of " + tSampleSize + " Americans")
+ " " + tAgeFilter.agePhrase
+ " from the 2003 "
+ " from the 2017-2020 Pre-Pandemic "
+ "<a href='https://www.cdc.gov/nchs/nhanes/index.htm' target='_blank'>NHANES</a>.</p> "
+ "<p>The variables you will get are: "
+ "<b>" + aList.join("</b>, <b>") + "</b>.</p>";

document.getElementById("sampleSummaryDiv").innerHTML = out;
}
};
};
Loading

0 comments on commit 17fe88d

Please sign in to comment.