Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove last , from JSON #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 198 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@

# Created by https://www.gitignore.io/api/node,macos

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

### JupyterNotebook ###
.ipynb_checkpoints
*/.ipynb_checkpoints/*

# Remove previous ipynb_checkpoints
# git rm -r .ipynb_checkpoints/
#
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "datauniverse",
"version": "0.1.0",
"description": "Visualization on the NASA's Data Universe",
"main": "index.js",
"directories": {
"example": "example"
},
"scripts": {
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/chucheria/DataUniverse.git"
},
"keywords": [
"nasa",
"data",
"d3",
"visualization",
"dataviz"
],
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/chucheria/DataUniverse/issues"
},
"homepage": "https://github.com/chucheria/DataUniverse#readme"
}
74 changes: 38 additions & 36 deletions source/create_json_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import string
import numpy
from nltk.corpus import stopwords
from os import SEEK_END

from collections import Counter

Expand All @@ -10,62 +11,63 @@
all_tags = []
unique_tags = []

#put tags of each line as nodes into the json file
for x in range (0, my_data.size):
# put tags of each line as nodes into the json file
for x in range(0, my_data.size):
string = (my_data[(x)][0]).decode('utf8')
newstr = string.strip()
all_tags.append(newstr.split(','))

json_file = open("nodes.json", "w")
json_file.write("[")

#todo: remove whitespaces, remove "", add unique entries to connections
# Remove whitespaces, remove "", add unique entries to connections
for tags in all_tags:
for single_tag in tags:
tagtoadd = single_tag.strip()
tagtoadd = tagtoadd.replace('"','')
if not tagtoadd.isdigit():
if tagtoadd not in unique_tags:
unique_tags.append(tagtoadd)
json_file.write("{")
json_file.write("\"name\": \""+tagtoadd+"\"")
json_file.write("},")
for single_tag in tags:
tagtoadd = single_tag.strip()
tagtoadd = tagtoadd.replace('"', '')
if not tagtoadd.isdigit():
if tagtoadd not in unique_tags:
unique_tags.append(tagtoadd)
json_file.write("{")
json_file.write("\"name\": \"" + tagtoadd + "\"")
json_file.write("},")

#todo: remove last ,
#json_file.seek(0,2) # end of file
#size=json_file.tell() # the size...
#json_file.truncate(size-1) # truncate at that size - how ever many characters
# Remove last ,
json_file.seek(-1, SEEK_END)
json_file.truncate()

# Close JSON
json_file.write("]")
json_file.close

connected_tags = [[]]*len(unique_tags)
connected_tags = [[]] * len(unique_tags)

print len(unique_tags)


#create links between related tags and write to json file
# create links between related tags and write to json file
json_links_file = open("links.json", "w")

json_links_file.write("[")

for lines in all_tags:
for single_tag in lines:
if single_tag in unique_tags:
#print single_tag # tag gefunden
for tagtoadd in lines:
if not tagtoadd.strip().isdigit():
if unique_tags.index(tagtoadd.strip()) != unique_tags.index(single_tag):#in unique_tags:
#print str(unique_tags.index(single_tag))+" "+str(unique_tags.index(tagtoadd.strip()))
json_links_file.write("{ \"source\": "+str(unique_tags.index(single_tag))+",")
connected_tags[unique_tags.index(single_tag)].append(tagtoadd)
json_links_file.write("\"target\": "+str(unique_tags.index(tagtoadd.strip()))+"},")
break
for single_tag in lines:
if single_tag in unique_tags:
# print single_tag # tag gefunden
for tagtoadd in lines:
if not tagtoadd.strip().isdigit():
# in unique_tags:
if unique_tags.index(tagtoadd.strip()) != unique_tags.index(single_tag):
# print str(unique_tags.index(single_tag))+" "+str(unique_tags.index(tagtoadd.strip()))
json_links_file.write(
"{ \"source\": \"" + single_tag + "\",")
connected_tags[unique_tags.index(
single_tag)].append(tagtoadd)
json_links_file.write(
"\"target\": \"" + tagtoadd.strip() + "\"},")
break

#todo: remove last ,
#json_links_file.seek(0,2) # end of file
#size=json_links_file.tell() # the size...
#json_links_file.truncate(size-1) # truncate at that size - how ever many characters
# Remove last ,
json_links_file.seek(-1, SEEK_END)
json_links_file.truncate()

json_links_file.write("]")
json_links_file.close
json_links_file.close
18 changes: 9 additions & 9 deletions source/data_universe.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</script>
<script
type="text/javascript"
src="http://d3js.org/queue.v1.min.js">
src="http://d3js.org/queue.v1.min.js">
</script>
</head>
<body>
<script type="text/javascript">

/* Set the diagrams Height & Width */
var h = 8000, w = 8000;
/* Set the color scale we want to use */
Expand All @@ -27,7 +27,7 @@
/* Build the directional arrows for the links/edges */
svg.append("svg:defs")
.selectAll("marker")
.data(["end"])
.data(["end"])
.enter().append("svg:marker")
.attr("id", String)
.attr("viewBox", "0 -5 10 10")
Expand All @@ -40,9 +40,9 @@
.attr("d", "M0,-5L10,0L0,5");
/* Pre-Load the json data using the queue library */
queue()
.defer(d3.json, "nodes.json")
.defer(d3.json, "links.json")
.await(makeDiag);
.defer(d3.json, "https://raw.githubusercontent.com/chucheria/DataUniverse/master/example/nodes.json")
.defer(d3.json, "https://raw.githubusercontent.com/chucheria/DataUniverse/master/example/links.json")
.await(makeDiag);
/* Define the main worker or execution function */
function makeDiag(error, nodes, links, table) {
/* Establish the dynamic force behavor of the nodes */
Expand Down Expand Up @@ -70,8 +70,8 @@
.attr("fill", "black")
.attr("font-family", "sans-serif")
.attr("font-size", "40px")
.text(function(d) { return d.name; });
/* Draw the nodes themselves */
.text(function(d) { return d.name; });
/* Draw the nodes themselves */
var nodes = svg.selectAll("circle")
.data(nodes)
.enter()
Expand All @@ -95,4 +95,4 @@
}; // End makeDiag worker func
</script>
</body>
</html>
</html>
Loading