Skip to content

Instantly share code, notes, and snippets.

View GraylinKim's full-sized avatar

Graylin Kim GraylinKim

View GitHub Profile
@GraylinKim
GraylinKim / JsonEncoder.py
Created September 6, 2013 15:41
Prototype of sc2reader json encoder. Basically a port of the existing toDict functionality.
class JSONEncoder(json.JSONEncoder):
def __init__(self, dateformat="%Y-%m-%d %H:%M:%S"):
self.dateformat = dateformat
def default(self, obj):
if isinstance(obj, datetime):
obj = obj.strftime(self.dateformat)
elif isinstance(obj, sc2reader.events.ChatEvent):
return self.default({
'time': obj.time.seconds,
/*
Missing dictionary keys can get filled at runtime with defaults.
classifications allow us to answer "is a" questions.
*/
/*
base_unit allows for basic inheritance of missing fields from other units.
At least 3 classifications: worker, army, building. Units like spine crawler may be army and building.
*/
units = [
@GraylinKim
GraylinKim / engine.py
Created April 3, 2013 20:40
Prototype of the sc2reader event engine.
from __future__ import absolute_import
import operator
import collections
from bisect import bisect_left
from sc2reader.events import *
class Engine(object):
""" Engine Specification
@GraylinKim
GraylinKim / newdata.py
Created September 17, 2011 19:32
A new method for generating multiple data dicts with inheritance
class MetaData(type):
def __new__(self,clsname,bases,dct):
#The base class is the exception to the rule
if clsname == 'BaseData':
return type.__new__(self,clsname,bases,dct)
def getSC2Classes(dct):
filter = lambda v: hasattr(v, '__bases__') and Object in v.__mro__
return [value for key,value in dct.iteritems() if filter(value)]
// Exceptions - Allow for catching of anticipated vs. unanticipated
//
class OpenLegislationException extends Exception { }
class PluginException extends OpenLegislationException {}
class LoaderException extends OpenLegislationException {}
// Primary work flow. Directs the ingest process at a high level
//
class Ingest<T extends Collection<V>,V extends BaseObject> {
Loader<T,V> loader;
@GraylinKim
GraylinKim / get_files.py
Created July 18, 2011 06:45
Function to return a list of files from a directory respecting recursion limits, allowing directory exclusion, and filtering based on filename.
def allow(file, include_regex=None):
name, ext = os.path.splitext(file)
if ext.lower() != ".sc2replay":
return False
elif include_regex and not re.match(include_regex,name):
return False
else:
return True
def get_files( location, include_regex=None,
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from helper import AttributeDict
import calendar, datetime
import sc2reader
from sc2reader.config import DefaultConfig
Traceback (most recent call last):
File "/home/Observatory/observatory/dashboard/fetch/fetch_repositories.py", line 127, in <module>
project.calculate_score()
File "/home/Observatory/observatory/dashboard/models/Project.py", line 99, in calculate_score
self.save()
File "/home/Observatory/observatory/dashboard/models/Project.py", line 73, in save
super(Project, self).save(*args, **kwargs)
File "/home/Observatory/observatory/dashboard/models/URLPathedModel.py", line 27, in save
super(URLPathedModel, self).save(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 460, in save
<response>
<metadata>
<status_code>200</status_code>
<status_msg>SUCCESS</status_msg>
<num_results>1</num_results>
</metadata>
<results>
<result>
<uid></uid>
<firstName>Graylin</firstName>
@GraylinKim
GraylinKim / person.xml
Created November 23, 2010 01:52
<doc> <str name="bio"> </str> <str name="department">Senator Thomas K. Duane</str> <str name="email">chausow@nysenate.gov</str> <str name="email2"> </str> <str name="facebook"> </str> <str name="firstName">Jared</str> <str name="ful
<doc>
<str name="bio"> </str>
<str name="department">Senator Thomas K. Duane</str>
<str name="email">chausow@nysenate.gov</str>
<str name="email2"> </str>
<str name="facebook"> </str>
<str name="firstName">Jared</str>
<str name="fullName">Jared Chausow</str>