Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

original working version

  • Loading branch information...
commit 174501460d87a5dd9e5b4857c7d015b6f255f387 0 parents
Tim Richardson authored
0  __init__.py
No changes.
BIN  __init__.pyc
Binary file not shown
14 manage.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+import imp
+try:
+ imp.find_module('settings') # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
+ sys.exit(1)
+
+import settings
+
+if __name__ == "__main__":
+ execute_manager(settings)
148 settings.py
@@ -0,0 +1,148 @@
+# Django settings for discorrelate project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@example.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': '/home/tim/workspace/discorrelate/src/sqlite.db', # Or path to database file if using sqlite3.
+ 'USER': '', # Not used with sqlite3.
+ 'PASSWORD': '', # Not used with sqlite3.
+ 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
+ 'PORT': '', # Set to empty string for default. Not used with sqlite3.
+ }
+}
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# On Unix systems, a value of None will cause Django to use the same
+# timezone as the operating system.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale
+USE_L10N = True
+
+# Absolute filesystem path to the directory that will hold user-uploaded files.
+# Example: "/home/media/media.lawrence.com/media/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash.
+# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
+MEDIA_URL = ''
+
+# Absolute path to the directory static files should be collected to.
+# Don't put anything in this directory yourself; store your static files
+# in apps' "static/" subdirectories and in STATICFILES_DIRS.
+# Example: "/home/media/media.lawrence.com/static/"
+STATIC_ROOT = '/home/tim/workspace/discorrelate/src/discorrelate/staticroot/'
+
+# URL prefix for static files.
+# Example: "http://media.lawrence.com/static/"
+STATIC_URL = '/static/'
+
+# URL prefix for admin static files -- CSS, JavaScript and images.
+# Make sure to use a trailing slash.
+# Examples: "http://foo.com/static/admin/", "/static/admin/".
+ADMIN_MEDIA_PREFIX = '/static/admin/'
+
+# Additional locations of static files
+STATICFILES_DIRS = (
+ # Put strings here, like "/home/html/static" or "C:/www/django/static".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+ '/home/tim/workspace/discorrelate/src/discorrelate/static/',
+)
+
+# List of finder classes that know how to find static files in
+# various locations.
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = 'a6%_ko*@*9n$r6w7460-jue1llog8fo0l5(96&uxhjch!tk1ry'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+# 'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware'
+)
+
+ROOT_URLCONF = 'discorrelate.urls'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+ "/home/tim/workspace/discorrelate/src/discorrelate/templates"
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ # Uncomment the next line to enable the admin:
+ # 'django.contrib.admin',
+ # Uncomment the next line to enable admin documentation:
+ # 'django.contrib.admindocs',
+)
+
+# A sample logging configuration. The only tangible logging
+# performed by this configuration is to send an email to
+# the site admins on every HTTP 500 error.
+# See http://docs.djangoproject.com/en/dev/topics/logging for
+# more details on how to customize your logging configuration.
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'handlers': {
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'class': 'django.utils.log.AdminEmailHandler'
+ }
+ },
+ 'loggers': {
+ 'django.request': {
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ }
+}
BIN  settings.pyc
Binary file not shown
1  static/d3
@@ -0,0 +1 @@
+Subproject commit 9a8b38370b8d8df63537d9189ace3acb5dffa470
2  static/test
@@ -0,0 +1,2 @@
+hello
+
128 templates/root.html
@@ -0,0 +1,128 @@
+<!doctype html>
+<head>
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
+<style type="text/css">
+svg{
+ position:absolute;
+ top:0;
+ left:0;
+ z-index:-1;
+}
+form{
+ position:absolute;
+ left:1em;
+ top:1em;
+}
+circle {
+ stroke-width: 1.5px;
+}
+
+line {
+ stroke: #999;
+}
+.nodetext { pointer-events: none; font: 10px sans-serif; }
+
+</style>
+<script type="text/javascript">
+$(document).ready(function(data) {
+ $('form').submit(function(e){
+ e.preventDefault();
+ var url = $('input[name="url"]').val();
+ var query = $('select[name="query"]').val();
+ var csrfmiddlewaretoken = $('input[name="csrfmiddlewaretoken"]').val();
+ $.ajax({
+ type : 'POST',
+ url : '/',
+ data: {
+ url : url,
+ query : query,
+ csrfmiddlewaretoken : csrfmiddlewaretoken
+ },
+ success : function(json){
+ var w = $(window).width(),
+ h = $(window).height(),
+ r = 10,
+ fill = d3.scale.category20();
+
+ var force = d3.layout.force()
+ .gravity(.01)
+ .charge(-50)
+ .linkDistance(60)
+ .size([w, h]);
+
+ var svg = d3.select("body").append("svg:svg")
+ .attr("width", w)
+ .attr("height", h);
+
+ var link = svg.selectAll("line")
+ .data(json.links)
+ .enter().append("svg:line");
+
+ var node = svg.selectAll("g.node")
+ .data(json.nodes)
+ .enter().append("svg:g")
+ .attr("class", "node")
+ .call(force.drag);
+
+ node
+ .append("svg:circle")
+ .attr("r", r - .75)
+ .style("fill", function(d) { return fill(d.group); })
+ .style("stroke", function(d) { return d3.rgb(fill(d.group)).darker(); });
+
+ node
+ .append("svg:title")
+ .text(function(d) { return d.artist; });
+
+ node
+ .append("svg:text")
+ .attr("class", "nodetext")
+ .attr("dx", 12)
+ .attr("dy", ".3em")
+ .text(function(d) { return d.name; });
+
+ force
+ .nodes(json.nodes)
+ .links(json.links)
+ .on("tick", tick)
+ .start();
+
+ function tick() {
+
+ force.start();
+
+ node
+ .attr("transform", function(d) {
+ //return "translate(" + ((d.x - d.px)+w/2) + "," + ((d.y - d.py)+h/2) + ")";
+ return "translate(" + d.x + "," + d.y + ")";
+ });
+
+ link.attr("x1", function(d) { return d.source.x; })
+ .attr("y1", function(d) { return d.source.y; })
+ .attr("x2", function(d) { return d.target.x; })
+ .attr("y2", function(d) { return d.target.y; });
+
+ }
+ }
+ });
+ });
+});
+</script>
+</head>
+<body>
+<form method="">
+ {% csrf_token %}
+ <input name="url" type="text" value="Use Discogs URL here"/>
+ <select name="query">
+ <option value="labels">Linked by label</option>
+ <option value="colabs">Colaborations</option>
+ <option value="comps">On compilations together</option>
+ </select>
+ <input type="submit" value="find" id="submit-button"/>
+</form>
+<div id="result"></div>
+<script type="text/javascript" src="{{ STATIC_URL }}d3/d3.js"></script>
+<script type="text/javascript" src="{{STATIC_URL}}d3/d3.geom.js"></script>
+<script type="text/javascript" src="{{STATIC_URL}}d3/d3.layout.js"></script>
+</body>
+</html>
106 urls.py
@@ -0,0 +1,106 @@
+from django.conf.urls.defaults import patterns, include, url
+from django.shortcuts import render_to_response, HttpResponse
+from django.core.context_processors import csrf
+from django.core import serializers
+from django.utils import simplejson
+from django.template import RequestContext
+
+from json import JSONEncoder
+import pytassium
+
+def SPARQLAndRespond(dataset, query):
+ response, data = dataset.select(query)
+ if response.status in range(200,300):
+ # data now contains a dictionary of results
+ #import pprint
+ #pprint.pprint(data)
+ return data
+ else:
+ print "Oh no! %d %s " % (response.status, response.reason)
+ return False
+
+def jsonTree(s, p, o):
+ sent = dict()
+ sent[s[0][0]] = s[1][0][s[0][0]].decode()
+ objects = dict()
+ for i, result in enumerate(o[1]):
+ node = dict()
+ for varName in result:
+ node[varName] = result[varName].decode()
+ objects['node'+str(i)] = node
+ sent[p] = objects
+ return simplejson.dumps(sent)
+
+def jsonNodeLink(s,p,o):
+ nodes = []
+ links = []
+ nodes.append({s[0][0] : s[1][0][s[0][0]].decode()})
+ for i, result in enumerate(o[1]):
+ node = dict()
+ for varName in result:
+ node[varName] = result[varName].decode()
+ nodes.append(node)
+ links.append({'source':0,'target':i+1,'value':10})
+ return simplejson.dumps({'nodes':nodes, 'links':links})
+
+def root(request):
+ if not request.POST:
+ c = RequestContext(request, {})
+ c.update(csrf(request))
+ return render_to_response('root.html',c)
+ url = request.POST.get('url')
+ query = request.POST.get('query')
+
+ if query == 'labels':
+ q = """
+ PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+ PREFIX mo: <http://purl.org/ontology/mo/>
+ SELECT DISTINCT ?artist ?name WHERE{
+ <""" + url + """> foaf:made ?release.
+ ?release mo:publisher ?label.
+ ?release2 mo:publisher ?label.
+ ?artist foaf:made ?release2.
+ ?artist foaf:name ?name.
+ }
+ """
+
+ elif query == 'colabs':
+ q = """
+ PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+ PREFIX mo: <http://purl.org/ontology/mo/>
+ PREFIX dc: <http://purl.org/dc/terms/>
+ SELECT DISTINCT ?artist ?name WHERE{
+ <""" + url + """> foaf:made ?release.
+ ?artist foaf:made ?release.
+ ?artist foaf:name ?name.
+ }
+ """
+
+ elif query == 'comps':
+ q = """
+ PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+ PREFIX mo: <http://purl.org/ontology/mo/>
+ PREFIX dc: <http://purl.org/dc/terms/>
+ SELECT DISTINCT ?artist ?name WHERE{
+ <""" + url + """> foaf:made ?release.
+ ?artist foaf:made ?release.
+ ?artist foaf:name ?name.
+ }
+ """
+
+ apiKey = '5dac588049e18e51fead5e788dc2449e38c2077a'
+ Discogs = pytassium.Dataset('discogs', apiKey)
+
+ rootQuery = """PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+ Select ?name where{<""" + url + """> foaf:name ?name.
+ }"""
+ subject = SPARQLAndRespond(Discogs, rootQuery)
+ results = SPARQLAndRespond(Discogs, q)
+
+ jsonny = jsonNodeLink(subject, query, results)
+
+ return HttpResponse(jsonny, content_type="application/json; charset=utf8")
+
+urlpatterns = patterns('',
+ url(r'^$', root)
+)
BIN  urls.pyc
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.