Skip to content

Commit

Permalink
1. Modified imports to use six.moves where applicable for Python2/3 c…
Browse files Browse the repository at this point in the history
…ompatibility

2. Moved referenced files to 'data' folder
3. Modified MANIFEST.in for recursive expansion and incorporation of data files.4. Updated revision
  • Loading branch information
davidkuhta committed Dec 27, 2017
1 parent a7f9729 commit ccea891
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ref/build_versions.json
recursive-include dasc2/data *
6 changes: 3 additions & 3 deletions dasc2/bin/build_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __create_unit_dict():
Dictionary: { unit_id : unit_name } <int> : <string>
"""

with open(resource_filename(__name__, '../ref/units.json')) as units_data:
with open(resource_filename(__name__, '../data/units_simple.json')) as units_data:
units = json.load(units_data)
unit_ids = { int(unit_id) : name for unit_id, name in units.items()}
return unit_ids
Expand Down Expand Up @@ -90,8 +90,8 @@ def build_order(states, unit_id_dict):
labeled_commanding_b_o = __label_units(commanding_b_o, unit_id_dict)
labeled_opposing_b_o = __label_units(opposing_b_o, unit_id_dict)

build_data = { "Commanding " : labeled_commanding_b_o.keys(),
"Opposing" : labeled_opposing_b_o.keys() }
build_data = { "Commanding " : list(labeled_commanding_b_o.keys()),
"Opposing" : list(labeled_opposing_b_o.keys()) }

return build_data

Expand Down
8 changes: 2 additions & 6 deletions dasc2/bin/download_replays.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@
import argparse
import shutil

# support both python 2 & 3
try:
import urlparse as urlparser
except ImportError:
import urllib.parse as urlparser

import six
from six.moves.urllib import parse as urlparser

from dasc2.lib.replay_helpers import check_build_version

Expand Down
17 changes: 11 additions & 6 deletions dasc2/bin/extract_replays.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import sys
sys.path.insert(0, '../')

import six
from six.moves import input

def extract_replays(archives_dir, replays_dir, password, remove=False):
"""Function which extracts replays
Args:
Expand Down Expand Up @@ -67,7 +70,7 @@ def __prompt_for_licensing_agreement(license_agreement):
valid_option = {"iagreetotheeula": "iagreetotheeula", "no": False, "n": False}

# Create user prompt
prompt = " [denoted password or 'No'] \n"
prompt = " [denoted password or 'No'] \n\n"

# Intialize counter
count = 0
Expand All @@ -76,18 +79,20 @@ def __prompt_for_licensing_agreement(license_agreement):
# Output the license_agreement and prompt
sys.stdout.write(license_agreement + prompt)
# Assign user input to choice
try:
choice = raw_input().lower()
except NameError:
choice = input().lower()
#REMOVING
# try:
# choice = raw_input().lower()
# except NameError:
# choice = input().lower()
choice = input().lower()

# If user entires a valid option return it's corresponding value
if choice in valid_option:
return valid_option[choice]
# Else provide the user with three additional attempts
elif count < 3:
count += 1
sys.stdout.write("Please respond with the denoted password or 'no'.\n")
sys.stdout.write("Please respond with the denoted password or 'no'.\n\n")
else:
return False

Expand Down
2 changes: 0 additions & 2 deletions dasc2/bin/generate_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

from future.builtins import range
from websocket import _exceptions
import six
from six.moves import queue

from pysc2 import run_configs

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 15 additions & 3 deletions dasc2/lib/process_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""A module containing helper functions for processing SC2 minimaps"""

import numpy as np
import json

from collections import defaultdict
from dasc2.lib.minimap_processor import SC2MinimapProcessor, sf
Expand All @@ -34,7 +35,7 @@ def process_minimap(minimap, screen):
"Opposing" alignments
"""
mp = SC2MinimapProcessor(minimap, screen)

minimap_data = {
"Camera" : minimap[3,:,:].tolist(),
"PlayerID" : minimap[4,:,:].tolist(),
Expand All @@ -54,7 +55,7 @@ def process_minimap(minimap, screen):
"HPShields" : mp.hp_and_shields(4)
}
}

return minimap_data

def army_count(screen, alignment):
Expand Down Expand Up @@ -82,4 +83,15 @@ def army_count(screen, alignment):
for unit in gen:
army_dict[str(unit[0])] += unit[1]

return army_dict
return army_dict

class NumpyEncoder(json.JSONEncoder):
"""Modifies JSON encoder to correctly process JSON holding int64"""
def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
elif isinstance(obj, np.floating):
return float(obj)
elif isinstance(obj, np.ndarray):
return obj.tolist()
return json.JSONEncoder.default(self, obj)
2 changes: 1 addition & 1 deletion dasc2/lib/replay_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def check_build_version(build_version, return_label):
Raises error in the event of an unsupported build type
"""
# Process the build_versions JSON file
version_file = open(resource_filename(__name__, '../ref/build_versions.json')).read()
version_file = open(resource_filename(__name__, '../data/build_versions.json')).read()
versions = json.loads(version_file)

# Cast build_version to int if it's an int
Expand Down
4 changes: 2 additions & 2 deletions dasc2/lib/replay_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from s2clientprotocol import sc2api_pb2 as sc_pb

from dasc2.lib.stats import ProcessStats
from dasc2.lib.process_helpers import army_count, process_minimap
from dasc2.lib.process_helpers import army_count, process_minimap, NumpyEncoder

import numpy as np
import json
Expand Down Expand Up @@ -287,7 +287,7 @@ def process_replay(self, controller, replay_data, map_data,
"PlayerID" : player_id, "Won": won, "Race" : race,
"EnemyRace" : enemy_race, "States" : state_list }
with open(states_file, 'a') as outfile:
json.dump(final_state, outfile)
json.dump(final_state, outfile, cls=NumpyEncoder)

break

Expand Down
13 changes: 0 additions & 13 deletions dasc2/ref/__init__.py

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

setup(
name='daSC2',
version='0.2.1-dev3',
version='0.2.2-dev3',
description='Data Analytics Library for StarCraft II',
long_description=description,
author='David Kuhta',
Expand All @@ -44,7 +44,6 @@
'dasc2',
'dasc2.bin',
'dasc2.lib',
'dasc2.ref',
'dasc2.agent'
],
install_requires=[
Expand Down

0 comments on commit ccea891

Please sign in to comment.