In [ ]:
%run "../Functions/4. User comparison.ipynb"
In [ ]:
%run "../Functions/5. Game map analysis.ipynb"
In [ ]:
#rmdf[rmdf['type']=='gotourl'].dropna(axis='columns', how='all')
#rmdf['type'].unique()
#rmdf[rmdf['type']=='selectmenu'].dropna(axis='columns', how='all')
_types = ['gotourl']
rmdf = rmdfPlaytestPretestPosttestUniqueProfilesVolunteersPhase1.copy()
plotLocatedEvents(filterAndLocateEvents(_types, rmdf.copy()), _types)
In [ ]:
_types = ['gotourl']
rmdf = rmdfPlaytestPretestPosttestUniqueProfilesVolunteersPhase2.copy()
plotLocatedEvents(filterAndLocateEvents(_types, rmdf.copy()), _types)
In [ ]:
In [ ]:
_types = ['death']
rmdf = rmdfPlaytestPretestPosttestUniqueProfilesVolunteersPhase1.copy()
deathFilteredLocatedEvents1 = filterAndLocateEvents(_types, rmdf.copy())
In [ ]:
_types = ['death']
rmdf = rmdfPlaytestPretestPosttestUniqueProfilesVolunteersPhase2.copy()
deathFilteredLocatedEvents2 = filterAndLocateEvents(_types, rmdf.copy())
In [ ]:
kdemethod = 'scott'
fig = plotLocatedEvents(deathFilteredLocatedEvents2, _types, _kdeplot = True,
_kdebw=kdemethod,_kdecut=2,_kdeshade=True,_kdeshade_lowest=False,_kdecbar=False,_kdealpha=0.5
)
fig.savefig('game map kde ' + kdemethod + str(_types) + " Phase2")
In [ ]:
allDataPlaytestPretestPosttestUniqueProfilesVolunteersPhase1 = getAllUserVectorData(
getAllResponders(gfdfPlaytestPretestPosttestUniqueProfilesVolunteersPhase1),
_rmDF = rmdfPlaytestPretestPosttestUniqueProfilesVolunteersPhase1,
_gfDF = gfdfPlaytestPretestPosttestUniqueProfilesVolunteersPhase1,
_source = correctAnswers + demographicAnswers )
In [ ]:
# Plot scores on the map
In [ ]:
allData = allDataPlaytestPretestPosttestUniqueProfilesVolunteersPhase1.copy()
In [ ]:
for userId in filteredLocatedEvents1[QUserId]:
filteredLocatedEvents1.loc[
filteredLocatedEvents1.index[filteredLocatedEvents1[QUserId] == userId],
'score'] = allData.loc['scoreposttest', userId]
In [ ]:
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2
In [ ]:
## Contour test
In [ ]:
fig, ax = plt.subplots()
CS = ax.contour(X, Y, Z)
ax.clabel(CS, inline=1, fontsize=10)
ax.set_title('Simplest default with labels')
In [ ]:
len(filteredLocatedEvents1['x'])
In [ ]:
X = np.array(filteredLocatedEvents1['x']).reshape(10, 337)
Y = np.array(filteredLocatedEvents1['y']).reshape(10, 337)
Z = np.array(filteredLocatedEvents1['score']).reshape(10, 337)
In [ ]:
#plt.contour(X, Y, Z)
plt.imshow(Z)
In [ ]:
plt.pcolormesh(X,Y,Z)
plt.colorbar()
In [ ]:
rmdf = rmdfPlaytestPretestPosttestUniqueProfilesVolunteersPhase2.copy()
titlePart = "Phase2"
In [ ]:
#def getLastLocatedEvent(rmdf):
lastLocatedEvents = rmdf[~pd.isnull(rmdf['coordinates'])]
lastLocatedEvents = lastLocatedEvents.loc[:,[QUserId, 'userTime', 'coordinates', 'type', 'section']]\
.sort_values([QUserId, 'userTime'], ascending=[False, False])\
.groupby(QUserId)\
.first()
lastLocatedEvents[QUserId] = lastLocatedEvents.index
lastLocatedEvents.index = range(len(lastLocatedEvents))
#lastLocatedEvents
In [ ]:
_types = lastLocatedEvents['type'].unique()
lastEventsFilteredLocatedEvents = filterAndLocateEvents(_types, lastLocatedEvents.copy())
In [ ]:
kdemethod = 'scott'
fig = plotLocatedEvents(lastEventsFilteredLocatedEvents, _types, _kdeplot = True,
_kdebw=kdemethod,_kdecut=2,_kdeshade=True,_kdeshade_lowest=False,_kdecbar=False,_kdealpha=0.3,
)
fig.savefig('game map kde ' + kdemethod + " last events " + titlePart)
In [ ]:
allTypes = rmdf1522['type'].dropna().unique()
types = ["death", "reach", "add", "craft", "remove", "select", "selectmenu"]
craftTypes = ["add", "craft", "remove", "select"]
gameTypes = ["hint", "pickup", "newfurthest", "newownrecord", "configure", "end", "complete", "restart", "start"]
webTypes = ["gotostudy", "gotomooc"]
adminTypes = ["switchtogameversion", "switchfromgameversion", "webconfigure"]
In [ ]:
allTypes
In [ ]:
allLocatedEventsDF = filterAndLocateEvents(allTypes)
locatedEventsDF = filterAndLocateEvents(types)
craftLocatedEventsDF = filterAndLocateEvents(craftTypes)
gameLocatedEventsDF = filterAndLocateEvents(gameTypes)
webLocatedEventsDF = filterAndLocateEvents(webTypes)
adminLocatedEventsDF = filterAndLocateEvents(adminTypes)
In [ ]:
len(allLocatedEventsDF)
In [ ]:
print("minX=" + str(min(allLocatedEventsDF['x'])))
print("maxX=" + str(max(allLocatedEventsDF['x'])))
print("minY=" + str(min(allLocatedEventsDF['y'])))
print("maxY=" + str(max(allLocatedEventsDF['y'])))
In [ ]:
type(min(allLocatedEventsDF['x']))
In [ ]:
type(allLocatedEventsDF)
In [ ]:
allLocatedEventsDF.columns
In [ ]:
type(allLocatedEventsDF['x'].value_counts())
In [ ]:
allLocatedEventsDF['x'].value_counts().hist()
In [ ]:
allLocatedEventsDF['bucket'] = pd.cut(allLocatedEventsDF['x'], 10)
allLocatedEventsDF.head()
In [ ]:
newdf = allLocatedEventsDF[['bucket','x']].groupby('bucket').sum()
newdf.plot(kind='bar')
In [ ]:
allLocatedEventsDF['bucket'] = pd.cut(allLocatedEventsDF['y'], 10)
newdf = allLocatedEventsDF[['bucket','y']].groupby('bucket').sum()
#newdf.plot(kind='bar', orientation='horizontal')
newdf.plot.barh()
In [ ]:
%run "../Functions/5. Game map analysis.ipynb"
In [ ]:
constants = getConstants()
constants
In [ ]:
for event in allTypes:
plotLocatedEvents(allLocatedEventsDF, [event])
In [ ]:
plotLocatedEvents(allLocatedEventsDF, ['end', 'configure', 'restart'])
In [ ]:
plotLocatedEvents(allLocatedEventsDF, types)
In [ ]:
plotLocatedEvents(allLocatedEventsDF, craftTypes)
In [ ]:
plotLocatedEvents(allLocatedEventsDF, gameTypes)
In [ ]:
plotLocatedEvents(allLocatedEventsDF, webTypes)
In [ ]:
plotLocatedEvents(allLocatedEventsDF, adminTypes)
In [ ]:
rmdf1522.columns
In [ ]:
#rmdf1522['customData.chapter'].dropna().head()
In [ ]:
mapRelevantColumns = ['type', 'section', 'coordinates']
mapDF = rmdf1522.loc[:,mapRelevantColumns]
len(mapDF)
In [ ]:
mapDF = mapDF.dropna()
len(mapDF)
In [ ]:
mapDF = mapDF[mapDF["type"].isin(types)]
mapDF.head()
In [ ]:
tutorial1DF = mapDF[(mapDF['section'].str.startswith('tutorial1'))]
#sandbox2DF = mapDF[(mapDF['section'].str.startswith('sandbox'))]
tutorial1DF.head(2)
In [ ]:
len(tutorial1DF)
In [ ]:
tutorial1DF['x'] = tutorial1DF['coordinates']
tutorial1DF['y'] = tutorial1DF['coordinates']
In [ ]:
tutorial1DF.head(2)
In [ ]:
m = re.findall('-*\d+', '[-259, -713]')
m
In [ ]:
coordinates = re.findall('-*\d+', tutorial1DF['coordinates'][10])
coordinates
In [ ]:
subsetCount = 100
subset = tutorial1DF.head(subsetCount)
subset.index = range(0, subsetCount)
In [ ]:
f = FloatProgress(min=0, max=len(subset.index))
display(f)
for index in subset.index:
coordinates = re.findall('-*\d+', subset['coordinates'][index])
subset['x'][index] = coordinates[0]
subset['y'][index] = coordinates[1]
f.value += 1
In [ ]:
subset.head(2)
In [ ]:
types
In [ ]:
plt.figure(figsize=(15,15))
plt.axis('equal')
# c = ["black", "red", "blue", "green"]
c = ['black', 'red', 'blue', 'green', 'orange', 'purple', 'brown', 'pink', 'olive', 'cyan', ]
# a = [ 0.3, 1, 1,1 ]
a = [ 0.3, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]
scatters = {}
for i, t in enumerate(types):
pts = subset[subset["type"] == t]
x = pts["x"]
y = pts["y"]
scatters[t] = plt.plot(x, y, 'o', c=c[i], lw=0, alpha=a[i])
plt.legend([ x[0] for x in scatters.values()], list(scatters.keys()))
plt.show()
In [ ]:
_mapBackground = image.imread('../../images/map.png')
In [ ]:
type(_mapBackground)
In [ ]:
len(_mapBackground)
In [ ]:
len(_mapBackground[0])
In [ ]:
_mapBackground.shape
In [ ]:
#types = allTypes
subset = allLocatedEventsDF
In [ ]:
allLocatedEventsDF[allLocatedEventsDF['type'] == 'complete'].head(5)
In [ ]:
imgStartCoordinates = [833,432]
imgEndCoordinates = [1333,334]
constants = getConstants()
print(getGraphPosition(imgStartCoordinates, constants))
print(getGraphPosition(imgEndCoordinates, constants))
In [ ]:
# from image dimensions
print(getXGraphPosition(0, constants))
print(getXGraphPosition(1665, constants))
print(getYGraphPosition(890, constants))
print(getYGraphPosition(0, constants))
In [ ]:
gameStartCoordinates = [-229,-608]
gameEndCoordinates = [450,-475]
# only for '../../images/map.tutorial1.png'
imgStartCoordinates = [833,432]
imgEndCoordinates = [1333,334]
scaleX = (gameStartCoordinates[0]-gameEndCoordinates[0])/(imgStartCoordinates[0]-imgEndCoordinates[0])
scaleY = (gameStartCoordinates[1]-gameEndCoordinates[1])/(imgStartCoordinates[1]-imgEndCoordinates[1])
offsetX = gameStartCoordinates[0] - (imgStartCoordinates[0]*scaleX)
offsetY = gameStartCoordinates[1] - (imgStartCoordinates[1]*scaleY)
newConstants = pd.Series([scaleX,scaleY,offsetX,offsetY], index=['scaleX', 'scaleY', 'offsetX', 'offsetY'])
In [ ]:
#constants = getConstants()
constants = newConstants
plt.figure(figsize=(18,12))
# background map image display
mapBackground = image.imread('../../images/map.tutorial1.png')
# background image dimensions
minX = 0
maxX = mapBackground.shape[1]
minY = mapBackground.shape[0]
maxY = 0
plt.imshow(mapBackground, aspect='auto', zorder=-1, \
extent=(getXGraphPosition(minX,constants), \
getXGraphPosition(maxX,constants), \
getYGraphPosition(minY,constants), \
getYGraphPosition(maxY,constants)), \
alpha=0.5)
colors = ['black', 'red', 'blue', 'green', 'orange', 'purple', 'brown', 'pink', 'olive', 'cyan', ]
alphas = [ 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, ]
scatters = {}
for i, t in enumerate(types):
pts = subset[subset['type'] == t]
x = pts['x']
y = pts['y']
scatters[t] = plt.plot(x, y, 'o', c=colors[i], lw=0, alpha=alphas[i])
plt.legend([ x[0] for x in scatters.values()], list(scatters.keys()))
# graph dimensions and extrema on tutorial1
# minX=-1152
# maxX=539
# minY=-1161
# maxY=-100
plt.xlim([-1200, 600])
plt.ylim([-1220, -20])
plt.show()