Add CT3531 Database Systems II
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{determine\PYGZus{}grid}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,}\PYG{n}{y}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,14 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+c1}{\PYGZsh{} input: a pair of (x,y) co-ordinates}
|
||||
\PYG{c+c1}{\PYGZsh{} output: a string that identifies the grid}
|
||||
\PYG{k}{def} \PYG{n+nf}{determine\PYGZus{}grid}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{):}
|
||||
\PYG{n}{grid\PYGZus{}width} \PYG{o}{=} \PYG{l+m+mi}{29} \PYG{c+c1}{\PYGZsh{} width of each grid in metres}
|
||||
\PYG{n}{grid\PYGZus{}height} \PYG{o}{=} \PYG{l+m+mi}{15} \PYG{c+c1}{\PYGZsh{} height of each grid in metres}
|
||||
|
||||
\PYG{c+c1}{\PYGZsh{} determining the location of the grid using floor division}
|
||||
\PYG{n}{grid\PYGZus{}x} \PYG{o}{=} \PYG{n}{x} \PYG{o}{//} \PYG{n}{grid\PYGZus{}width}
|
||||
\PYG{n}{grid\PYGZus{}y} \PYG{o}{=} \PYG{n}{y} \PYG{o}{//} \PYG{n}{grid\PYGZus{}height}
|
||||
|
||||
\PYG{c+c1}{\PYGZsh{} return the grid identifier in the format `x.y`}
|
||||
\PYG{k}{return} \PYG{n+nb}{str}\PYG{p}{(}\PYG{n}{grid\PYGZus{}x}\PYG{p}{)} \PYG{o}{+} \PYG{l+s+s2}{\PYGZdq{}.\PYGZdq{}} \PYG{o}{+} \PYG{n+nb}{str}\PYG{p}{(}\PYG{n}{grid\PYGZus{}y}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{determine\PYGZus{}grid}\PYG{p}{(}\PYG{n}{x}\PYG{p}{,} \PYG{n}{y}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,3 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{n}{determine\PYGZus{}grid}\PYG{p}{()}
|
||||
\end{Verbatim}
|
@ -0,0 +1,29 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
\PYG{c+c1}{\PYGZsh{} function to return the times when two given players are in the same location}
|
||||
\PYG{c+c1}{\PYGZsh{} input: player ID of both players}
|
||||
\PYG{c+c1}{\PYGZsh{} output: array of timestamps}
|
||||
\PYG{k}{def} \PYG{n+nf}{same\PYGZus{}times}\PYG{p}{(}\PYG{n}{player1}\PYG{p}{,} \PYG{n}{player2}\PYG{p}{,} \PYG{n}{grid}\PYG{p}{):}
|
||||
\PYG{c+c1}{\PYGZsh{} get the times both players are in the given grid}
|
||||
\PYG{n}{player1\PYGZus{}times} \PYG{o}{=} \PYG{n}{query}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}select times from table @ \PYGZdq{}} \PYG{o}{+} \PYG{n+nb}{hash}\PYG{p}{(}\PYG{n}{player1}\PYG{p}{,} \PYG{n}{grid}\PYG{p}{))}
|
||||
\PYG{n}{player2\PYGZus{}times} \PYG{o}{=} \PYG{n}{query}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}select times from table @ \PYGZdq{}} \PYG{o}{+} \PYG{n+nb}{hash}\PYG{p}{(}\PYG{n}{player2}\PYG{p}{,} \PYG{n}{grid}\PYG{p}{))}
|
||||
|
||||
\PYG{n}{same\PYGZus{}times} \PYG{o}{=} \PYG{p}{[]}
|
||||
|
||||
\PYG{c+c1}{\PYGZsh{} index i for player1\PYGZus{}times and index j for player2\PYGZus{}times}
|
||||
\PYG{n}{i} \PYG{o}{=} \PYG{n}{j} \PYG{o}{=} \PYG{l+m+mi}{0}
|
||||
|
||||
\PYG{k}{while} \PYG{n}{i} \PYG{o}{\PYGZlt{}} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{player1\PYGZus{}times}\PYG{p}{)} \PYG{o+ow}{and} \PYG{n}{j} \PYG{o}{\PYGZlt{}} \PYG{n+nb}{len}\PYG{p}{(}\PYG{n}{player2\PYGZus{}times}\PYG{p}{):}
|
||||
\PYG{k}{if} \PYG{n}{player1\PYGZus{}times}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]} \PYG{o}{==} \PYG{n}{player2\PYGZus{}times}\PYG{p}{[}\PYG{n}{j}\PYG{p}{]:}
|
||||
\PYG{c+c1}{\PYGZsh{} both players are in the grid cell at this time}
|
||||
\PYG{n}{same\PYGZus{}times}\PYG{o}{.}\PYG{n}{append}\PYG{p}{(}\PYG{n}{player1\PYGZus{}times}\PYG{p}{[}\PYG{n}{i}\PYG{p}{])}
|
||||
\PYG{n}{i} \PYG{o}{+=} \PYG{l+m+mi}{1}
|
||||
\PYG{n}{j} \PYG{o}{+=} \PYG{l+m+mi}{1}
|
||||
\PYG{k}{else} \PYG{k}{if} \PYG{n}{player2\PYGZus{}times}\PYG{p}{[}\PYG{n}{j}\PYG{p}{]} \PYG{o}{\PYGZgt{}} \PYG{n}{player1\PYGZus{}times}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]:}
|
||||
\PYG{c+c1}{\PYGZsh{} increment the player1 index (i) as it\PYGZsq{}s smaller than the time at j}
|
||||
\PYG{n}{i} \PYG{o}{+=} \PYG{l+m+mi}{1}
|
||||
\PYG{k}{else}\PYG{p}{:}
|
||||
\PYG{c+c1}{\PYGZsh{} increment the player2 index (j) as it\PYGZsq{}s smaller than the time at i}
|
||||
\PYG{n}{j} \PYG{o}{+=} \PYG{l+m+mi}{1}
|
||||
|
||||
\PYG{k}{return} \PYG{n}{same\PYGZus{}times}
|
||||
\end{Verbatim}
|
@ -0,0 +1,27 @@
|
||||
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8\relax}]
|
||||
\PYG{c+c1}{\PYGZsh{} function to determine the number of times a given player was in a given grid}
|
||||
\PYG{c+c1}{\PYGZsh{} input: player ID, grid identifier}
|
||||
\PYG{c+c1}{\PYGZsh{} output: count of the number of times that player ID was recorded in that grid}
|
||||
\PYG{k}{def} \PYG{n+nf}{player\PYGZus{}grid\PYGZus{}values}\PYG{p}{(}\PYG{n}{player\PYGZus{}id}\PYG{p}{,} \PYG{n}{grid\PYGZus{}id}\PYG{p}{):}
|
||||
\PYG{c+c1}{\PYGZsh{} get table location on disk}
|
||||
\PYG{n}{table\PYGZus{}location} \PYG{o}{=} \PYG{n+nb}{hash}\PYG{p}{(}\PYG{n}{player\PYGZus{}id}\PYG{p}{,} \PYG{n}{grid\PYGZus{}id}\PYG{p}{)}
|
||||
|
||||
\PYG{c+c1}{\PYGZsh{} query the number of rows in that table using some pseudo-SQL nonsense}
|
||||
\PYG{n}{count} \PYG{o}{=} \PYG{n}{select}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}count(*) from table @ \PYGZdq{}} \PYG{o}{+} \PYG{n}{table\PYGZus{}location}\PYG{p}{)}
|
||||
|
||||
\PYG{k}{return} \PYG{n}{count}
|
||||
|
||||
\PYG{c+c1}{\PYGZsh{} function to generate a an array of heatmap values for every location on the pitch}
|
||||
\PYG{c+c1}{\PYGZsh{} input: an array of locations on the pitch, an array of the player IDs in the game}
|
||||
\PYG{c+c1}{\PYGZsh{} output: an array numbers indicating the number of times a player was in each location}
|
||||
\PYG{k}{def} \PYG{n+nf}{generate\PYGZus{}heatmap}\PYG{p}{(}\PYG{n}{locations}\PYG{p}{,} \PYG{n}{players}\PYG{p}{):}
|
||||
\PYG{c+c1}{\PYGZsh{} output array will hold the number of times a player was in each location, in the same order as the locations array}
|
||||
\PYG{n}{heatmap\PYGZus{}values} \PYG{o}{=} \PYG{p}{[]} \PYG{c+c1}{\PYGZsh{} assume each index initialises to 0}
|
||||
|
||||
\PYG{c+c1}{\PYGZsh{} iterate over each location}
|
||||
\PYG{k}{for} \PYG{p}{(}\PYG{n+nb}{int} \PYG{n}{i} \PYG{o}{=} \PYG{l+m+mi}{0}\PYG{p}{;} \PYG{n}{i} \PYG{o}{\PYGZlt{}} \PYG{n}{locations}\PYG{o}{.}\PYG{n}{length}\PYG{p}{;} \PYG{n}{i}\PYG{o}{++}\PYG{p}{):}
|
||||
\PYG{c+c1}{\PYGZsh{} iterate over each player for each location}
|
||||
\PYG{k}{for} \PYG{p}{(}\PYG{n+nb}{int} \PYG{n}{j} \PYG{o}{=} \PYG{l+m+mi}{0}\PYG{p}{;} \PYG{n}{j} \PYG{o}{\PYGZlt{}} \PYG{n}{players}\PYG{o}{.}\PYG{n}{length}\PYG{p}{;} \PYG{n}{j}\PYG{o}{++}\PYG{p}{):}
|
||||
\PYG{n}{player\PYGZus{}id} \PYG{o}{=} \PYG{n}{players}\PYG{p}{[}\PYG{n}{j}\PYG{p}{]}
|
||||
\PYG{n}{heatmap\PYGZus{}values}\PYG{p}{[}\PYG{n}{i}\PYG{p}{]} \PYG{o}{+=} \PYG{n}{player\PYGZus{}grid\PYGZus{}values}\PYG{p}{(}\PYG{n}{player\PYGZus{}id}\PYG{p}{,} \PYG{n}{location}\PYG{p}{)}
|
||||
\end{Verbatim}
|
@ -0,0 +1,76 @@
|
||||
|
||||
\makeatletter
|
||||
\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax%
|
||||
\let\PYG@ul=\relax \let\PYG@tc=\relax%
|
||||
\let\PYG@bc=\relax \let\PYG@ff=\relax}
|
||||
\def\PYG@tok#1{\csname PYG@tok@#1\endcsname}
|
||||
\def\PYG@toks#1+{\ifx\relax#1\empty\else%
|
||||
\PYG@tok{#1}\expandafter\PYG@toks\fi}
|
||||
\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{%
|
||||
\PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}}
|
||||
\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}}
|
||||
|
||||
\@namedef{PYG@tok@c}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@cp}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@cs}{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@k}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@kd}{\let\PYG@bf=\textbf\let\PYG@it=\textit}
|
||||
\@namedef{PYG@tok@nb}{\let\PYG@bf=\textbf\let\PYG@it=\textit}
|
||||
\@namedef{PYG@tok@bp}{\let\PYG@bf=\textbf\let\PYG@it=\textit}
|
||||
\@namedef{PYG@tok@nn}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@nc}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@nf}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@nv}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@no}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@ow}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@s}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@err}{\def\PYG@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}}
|
||||
\@namedef{PYG@tok@kc}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@kn}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@kp}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@kr}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@kt}{\let\PYG@bf=\textbf}
|
||||
\@namedef{PYG@tok@fm}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@vc}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@vg}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@vi}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@vm}{\let\PYG@bf=\textbf\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sa}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sb}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sc}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@dl}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sd}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@s2}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@se}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sh}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@si}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sx}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@sr}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@s1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@ss}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
|
||||
\@namedef{PYG@tok@ch}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@cm}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@cpf}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
\@namedef{PYG@tok@c1}{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
|
||||
|
||||
\def\PYGZbs{\char`\\}
|
||||
\def\PYGZus{\char`\_}
|
||||
\def\PYGZob{\char`\{}
|
||||
\def\PYGZcb{\char`\}}
|
||||
\def\PYGZca{\char`\^}
|
||||
\def\PYGZam{\char`\&}
|
||||
\def\PYGZlt{\char`\<}
|
||||
\def\PYGZgt{\char`\>}
|
||||
\def\PYGZsh{\char`\#}
|
||||
\def\PYGZpc{\char`\%}
|
||||
\def\PYGZdl{\char`\$}
|
||||
\def\PYGZhy{\char`\-}
|
||||
\def\PYGZsq{\char`\'}
|
||||
\def\PYGZdq{\char`\"}
|
||||
\def\PYGZti{\char`\~}
|
||||
% for compatibility with earlier versions
|
||||
\def\PYGZat{@}
|
||||
\def\PYGZlb{[}
|
||||
\def\PYGZrb{]}
|
||||
\makeatother
|
||||
|
Reference in New Issue
Block a user