diff --git a/RWM-P2-TEAM-C/Assets/Scripts/BulletManager.cs b/RWM-P2-TEAM-C/Assets/Scripts/BulletManager.cs index 01749a5..3992a25 100644 --- a/RWM-P2-TEAM-C/Assets/Scripts/BulletManager.cs +++ b/RWM-P2-TEAM-C/Assets/Scripts/BulletManager.cs @@ -42,6 +42,8 @@ public void shootBullet() bulletPrefab.GetComponent().bulletManager = this; bulletPrefab.GetComponent().speed = bulletMoveSpeed; bulletPrefab.GetComponent().lifetime = bulletLifeTime; + + AnalyticsManager.instance.data.bulletsFired++; } } diff --git a/RWM-P2-TEAM-C/Assets/Scripts/OnDeath.cs b/RWM-P2-TEAM-C/Assets/Scripts/OnDeath.cs index c2f0f6c..0827ab2 100644 --- a/RWM-P2-TEAM-C/Assets/Scripts/OnDeath.cs +++ b/RWM-P2-TEAM-C/Assets/Scripts/OnDeath.cs @@ -27,6 +27,7 @@ public void LateUpdate() public void hasDied() { + AnalyticsManager.instance.data.deathCount++; StartCoroutine("deathAnimationPlaying"); } diff --git a/RWM-P2-TEAM-C/Assets/Scripts/Server/AnalyticsManager.cs b/RWM-P2-TEAM-C/Assets/Scripts/Server/AnalyticsManager.cs index e9e843a..dd6b435 100644 --- a/RWM-P2-TEAM-C/Assets/Scripts/Server/AnalyticsManager.cs +++ b/RWM-P2-TEAM-C/Assets/Scripts/Server/AnalyticsManager.cs @@ -3,21 +3,48 @@ using UnityEngine; using UnityEngine.Networking; using System.Net; +using UnityEngine.SceneManagement; [System.Serializable] public class GameState { - public int completion_time; + public int bulletsFired; + public int deathCount; + public int defeatedEnemies; public int level; } public class AnalyticsManager : MonoBehaviour { - public static IEnumerator PostMethod(GameState t_data) + public static AnalyticsManager instance = null; + public GameState data; + + void Awake() + { + if (instance == null) instance = this; + else if (instance != this) DestroyImmediate(gameObject); + + data.level = SceneManager.GetActiveScene().buildIndex; + DontDestroyOnLoad(gameObject); + } + + /// + /// Used to reset our Singleton's data back to the start + /// To be used when a new game is started. + /// + void resetdata() { - string jsonData = JsonUtility.ToJson(t_data); + data.bulletsFired = 0; + data.deathCount = 0; + data.defeatedEnemies = 0; + data.level = SceneManager.GetActiveScene().buildIndex; + } + + public IEnumerator PostMethod() + { + string jsonData = JsonUtility.ToJson(data); // uses pre-made data object - string url = "http://localhost:5000/upload_data"; + string url = "http://34.242.150.74/upload_data"; using (UnityWebRequest request = UnityWebRequest.Put(url, jsonData)) { request.method = UnityWebRequest.kHttpVerbPOST; @@ -32,4 +59,8 @@ public static IEnumerator PostMethod(GameState t_data) Debug.Log("Error sending data to the server: Error " + request.responseCode); } } + + void Start() { } + + void Update() { } } diff --git a/RWM-P2-TEAM-C/Assets/Scripts/Server/AnalyticsManager.cs.meta b/RWM-P2-TEAM-C/Assets/Scripts/Server/AnalyticsManager.cs.meta index 66c8990..8d3da94 100644 --- a/RWM-P2-TEAM-C/Assets/Scripts/Server/AnalyticsManager.cs.meta +++ b/RWM-P2-TEAM-C/Assets/Scripts/Server/AnalyticsManager.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 06222818e23649c4698ad03d84f415b7 +guid: 9be84d1ae0672514bb533ae1645cad89 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/server/Mantas_Josh.pem b/server/Mantas_Josh.pem new file mode 100644 index 0000000..7346bce --- /dev/null +++ b/server/Mantas_Josh.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAjiv6TR75vN9WH6KuOF7iwoMj3Kqo0Rc02Rz9fDVODQ/RGF9X +sQPCalUUk2HZAb0e00r9kfGf9s4XDCwKVnv9SZNNacA4pUMKAhSzvWITZtL/I8zM +iIp54agpl2bJ6lqYsrIMv0syIxBDE1+BB5KFJXaYvNh0lHkEfmFkNdJO8X1Rg0FA +aVFhEBj+n8fupribXabG0+17qhsH85F1q2pYvbxqxLVvQ9JeO4ZWeJs8WwQspClm +N7Ogf3uJmWxv99CQq7Mwv1lV3ozXWdkOpFQgFvRNsdwk3vUfV7WF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k4aEucDgXPbcmztQSRnNh601sd3VZWDUdGSWjhiZfg6W4CDN7vps/ob +EvP9AoGBAJpyrN11VrCgsMJGvHeu6pm9ugUFebYrBEF4T4awsG9hujI8AV/fdDPF +hdvKNOShHxZU7IGetA9KKIpm64ct73TrTBSTzuMd3XErItcF45nTDSt3eAug2VLJ +KPB7pSVV4bO3rsdZlZP3udjg2QyFcl7vFhYvrW1aV6hprg8x5Zgg +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/server/PythonDockerfile b/server/PythonDockerfile new file mode 100644 index 0000000..1f924eb --- /dev/null +++ b/server/PythonDockerfile @@ -0,0 +1,17 @@ +# Use an official Python runtime as a parent image +FROM python:3.8 + +RUN mkdir /app + +# Set the working directory to /app +WORKDIR /app + +# Copy the current directory contents into the container at /app +ADD /requirements.txt . + +# Install any needed packages specified in requirements.txt +RUN pip install -r requirements.txt + +# Run app.py when the container launches +# Note -u means unbuffered, otherwise there is no output to the logs +CMD ["python", "-u", "./basic_api.py"] diff --git a/server/__pycache__/api_basic_upload.cpython-38.pyc b/server/__pycache__/api_basic_upload.cpython-38.pyc new file mode 100644 index 0000000..4d143e9 Binary files /dev/null and b/server/__pycache__/api_basic_upload.cpython-38.pyc differ diff --git a/server/__pycache__/game_analytics.cpython-38.pyc b/server/__pycache__/game_analytics.cpython-38.pyc new file mode 100644 index 0000000..b2714e1 Binary files /dev/null and b/server/__pycache__/game_analytics.cpython-38.pyc differ diff --git a/server/__pycache__/game_analytics.cpython-39.pyc b/server/__pycache__/game_analytics.cpython-39.pyc new file mode 100644 index 0000000..30d1e11 Binary files /dev/null and b/server/__pycache__/game_analytics.cpython-39.pyc differ diff --git a/server/api_basic_upload.py b/server/api_basic_upload.py index 2df4cb9..6654ae3 100644 --- a/server/api_basic_upload.py +++ b/server/api_basic_upload.py @@ -1,12 +1,26 @@ from flask import Flask, request, Blueprint, make_response +import json +import datetime +import game_analytics api_basic_upload = Blueprint('api_basic_upload', __name__) @api_basic_upload.route('/upload_data', methods=['POST']) def post_upload(): try: + print("Grabbing data via POST method in post_upload") data = request.get_json() + print("Adding timestamp to data dict in post_upload") + data['timestamp'] = datetime.datetime.utcnow() print(data) + + print("Attempting connection to database in post_upload") + game_analytics.connect_to_database() + + print("Attempting to add data to database in post_upload") + game_analytics.add_data(data) + + print("Attempts successful, returning success.") return "{'status': 'success'}" except Exception as e: print(e) diff --git a/server/basic_api.py b/server/basic_api.py index 5a28d8d..1e8dea1 100644 --- a/server/basic_api.py +++ b/server/basic_api.py @@ -9,5 +9,5 @@ app.register_blueprint(api_basic_upload) -app.run(host='0.0.0.0', debug=True, use_reloader=True) +app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=True) diff --git a/server/docker-compose.yml b/server/docker-compose.yml new file mode 100644 index 0000000..e21f467 --- /dev/null +++ b/server/docker-compose.yml @@ -0,0 +1,31 @@ +version: "3.3" + +services: + + game_analytics: + build: + context: . + dockerfile: PythonDockerfile + ports: + - "80:5000" + tty: true + volumes: + - ./:/app + networks: + - net + + mongo: + image: mongo:4.2.2 + ports: + - "27017:27017" + environment: + - MONGO_INITDB_ROOT_USERNAME=test + - MONGO_INITDB_ROOT_PASSWORD=test + networks: + - net + volumes: + - ./mongo_db_data_container:/data/db + +networks: + net: + driver: bridge \ No newline at end of file diff --git a/server/game_analytics.py b/server/game_analytics.py new file mode 100644 index 0000000..d90fdf0 --- /dev/null +++ b/server/game_analytics.py @@ -0,0 +1,49 @@ +import pandas as pd +from pymongo import MongoClient + +db = {} + +def connect_to_database(): + print("Creating client in connect_to_database") + client = MongoClient('mongo', 27017, username="test", password="test") + + + global db + + print("Grabbing test_database in connect_to_database") + db = client.test_database + + print("Returning test_database in connect_to_database") + return db + +def connect_to_database_outside_docker(): + client = MongoClient('34.242.150.74', 80, username="test", password="test") + + global db + db = client.test_database + return db + + +def add_data(data): + print("Getting posts in database in add_data") + posts = db.posts + + print("Grabbing post_id using data in add_data") + post_id = posts.insert_one(data).inserted_id + + print("Post ID: " + str(post_id)) + +def get_dataframe(): + print("Initializing cursor in get_dataframe") + cursor = db.posts.find() # Expand the cursor and construct the DataFrame + + print(cursor) + + print("Creating pandas Dataframe in get_dataframe") + df = pd.DataFrame(list(cursor)) + + return df + + + + diff --git a/server/game_analytics.py.bak b/server/game_analytics.py.bak new file mode 100644 index 0000000..7988782 --- /dev/null +++ b/server/game_analytics.py.bak @@ -0,0 +1,34 @@ +import pandas as pd +from pymongo import MongoClient + +db = {} + +def connect_to_database(): + client = MongoClient('mongo', 80, username="test", password="test") + + global db + db = client.test_database + return db + +def connect_to_database_outside_docker(): + client = MongoClient('http://34.242.150.74/upload_data', 80, username="test", password="test") + + global db + db = client.test_database + return db + + +def add_data(data): + posts = db.posts + + post_id = posts.insert_one(data).inserted_id + +def get_dataframe(): + cursor = db.posts.find() + # Expand the cursor and construct the DataFrame + df = pd.DataFrame(list(cursor)) + return df + + + + diff --git a/server/mongo_db_data_container/WiredTiger b/server/mongo_db_data_container/WiredTiger new file mode 100644 index 0000000..d3aeec7 --- /dev/null +++ b/server/mongo_db_data_container/WiredTiger @@ -0,0 +1,2 @@ +WiredTiger +WiredTiger 3.2.2: (August 28, 2019) diff --git a/server/mongo_db_data_container/WiredTiger.lock b/server/mongo_db_data_container/WiredTiger.lock new file mode 100644 index 0000000..3d84206 --- /dev/null +++ b/server/mongo_db_data_container/WiredTiger.lock @@ -0,0 +1 @@ +WiredTiger lock file diff --git a/server/mongo_db_data_container/WiredTiger.turtle b/server/mongo_db_data_container/WiredTiger.turtle new file mode 100644 index 0000000..06bb400 --- /dev/null +++ b/server/mongo_db_data_container/WiredTiger.turtle @@ -0,0 +1,6 @@ +WiredTiger version string +WiredTiger 3.2.2: (August 28, 2019) +WiredTiger version +major=3,minor=2,patch=2 +file:WiredTiger.wt +access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=,cache_resident=false,checksum=uncompressed,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,value_format=S,version=(major=1,minor=1),checkpoint=(WiredTigerCheckpoint.14=(addr="018d81e47ca5c6b18e81e4c57ebada8f81e422b771c6808080e2efc0e22fc0",order=14,time=1646493484,size=24576,newest_durable_ts=0,oldest_start_ts=0,oldest_start_txn=0,newest_stop_ts=-1,newest_stop_txn=-11,write_gen=36)),checkpoint_lsn=(3,6144) diff --git a/server/mongo_db_data_container/WiredTiger.wt b/server/mongo_db_data_container/WiredTiger.wt new file mode 100644 index 0000000..297e03d Binary files /dev/null and b/server/mongo_db_data_container/WiredTiger.wt differ diff --git a/server/mongo_db_data_container/WiredTigerLAS.wt b/server/mongo_db_data_container/WiredTigerLAS.wt new file mode 100644 index 0000000..3f019cb Binary files /dev/null and b/server/mongo_db_data_container/WiredTigerLAS.wt differ diff --git a/server/mongo_db_data_container/_mdb_catalog.wt b/server/mongo_db_data_container/_mdb_catalog.wt new file mode 100644 index 0000000..873615a Binary files /dev/null and b/server/mongo_db_data_container/_mdb_catalog.wt differ diff --git a/server/mongo_db_data_container/collection-0--4831767958517668881.wt b/server/mongo_db_data_container/collection-0--4831767958517668881.wt new file mode 100644 index 0000000..79ab710 Binary files /dev/null and b/server/mongo_db_data_container/collection-0--4831767958517668881.wt differ diff --git a/server/mongo_db_data_container/collection-0--7489545417879759042.wt b/server/mongo_db_data_container/collection-0--7489545417879759042.wt new file mode 100644 index 0000000..c864c59 Binary files /dev/null and b/server/mongo_db_data_container/collection-0--7489545417879759042.wt differ diff --git a/server/mongo_db_data_container/collection-2--7489545417879759042.wt b/server/mongo_db_data_container/collection-2--7489545417879759042.wt new file mode 100644 index 0000000..927d55e Binary files /dev/null and b/server/mongo_db_data_container/collection-2--7489545417879759042.wt differ diff --git a/server/mongo_db_data_container/collection-4--7489545417879759042.wt b/server/mongo_db_data_container/collection-4--7489545417879759042.wt new file mode 100644 index 0000000..883f392 Binary files /dev/null and b/server/mongo_db_data_container/collection-4--7489545417879759042.wt differ diff --git a/server/mongo_db_data_container/collection-8--7489545417879759042.wt b/server/mongo_db_data_container/collection-8--7489545417879759042.wt new file mode 100644 index 0000000..725415f Binary files /dev/null and b/server/mongo_db_data_container/collection-8--7489545417879759042.wt differ diff --git a/server/mongo_db_data_container/diagnostic.data/metrics.2022-03-05T15-08-54Z-00000 b/server/mongo_db_data_container/diagnostic.data/metrics.2022-03-05T15-08-54Z-00000 new file mode 100644 index 0000000..2bf46e6 Binary files /dev/null and b/server/mongo_db_data_container/diagnostic.data/metrics.2022-03-05T15-08-54Z-00000 differ diff --git a/server/mongo_db_data_container/diagnostic.data/metrics.2022-03-05T15-09-29Z-00000 b/server/mongo_db_data_container/diagnostic.data/metrics.2022-03-05T15-09-29Z-00000 new file mode 100644 index 0000000..ee06513 Binary files /dev/null and b/server/mongo_db_data_container/diagnostic.data/metrics.2022-03-05T15-09-29Z-00000 differ diff --git a/server/mongo_db_data_container/diagnostic.data/metrics.2022-03-05T15-16-32Z-00000 b/server/mongo_db_data_container/diagnostic.data/metrics.2022-03-05T15-16-32Z-00000 new file mode 100644 index 0000000..22d402f Binary files /dev/null and b/server/mongo_db_data_container/diagnostic.data/metrics.2022-03-05T15-16-32Z-00000 differ diff --git a/server/mongo_db_data_container/index-1--4831767958517668881.wt b/server/mongo_db_data_container/index-1--4831767958517668881.wt new file mode 100644 index 0000000..a236149 Binary files /dev/null and b/server/mongo_db_data_container/index-1--4831767958517668881.wt differ diff --git a/server/mongo_db_data_container/index-1--7489545417879759042.wt b/server/mongo_db_data_container/index-1--7489545417879759042.wt new file mode 100644 index 0000000..04dc634 Binary files /dev/null and b/server/mongo_db_data_container/index-1--7489545417879759042.wt differ diff --git a/server/mongo_db_data_container/index-10--7489545417879759042.wt b/server/mongo_db_data_container/index-10--7489545417879759042.wt new file mode 100644 index 0000000..8c4a5c6 Binary files /dev/null and b/server/mongo_db_data_container/index-10--7489545417879759042.wt differ diff --git a/server/mongo_db_data_container/index-3--7489545417879759042.wt b/server/mongo_db_data_container/index-3--7489545417879759042.wt new file mode 100644 index 0000000..74ff1e9 Binary files /dev/null and b/server/mongo_db_data_container/index-3--7489545417879759042.wt differ diff --git a/server/mongo_db_data_container/index-5--7489545417879759042.wt b/server/mongo_db_data_container/index-5--7489545417879759042.wt new file mode 100644 index 0000000..333e00b Binary files /dev/null and b/server/mongo_db_data_container/index-5--7489545417879759042.wt differ diff --git a/server/mongo_db_data_container/index-6--7489545417879759042.wt b/server/mongo_db_data_container/index-6--7489545417879759042.wt new file mode 100644 index 0000000..737b0f9 Binary files /dev/null and b/server/mongo_db_data_container/index-6--7489545417879759042.wt differ diff --git a/server/mongo_db_data_container/index-9--7489545417879759042.wt b/server/mongo_db_data_container/index-9--7489545417879759042.wt new file mode 100644 index 0000000..935ba61 Binary files /dev/null and b/server/mongo_db_data_container/index-9--7489545417879759042.wt differ diff --git a/server/mongo_db_data_container/journal/WiredTigerLog.0000000003 b/server/mongo_db_data_container/journal/WiredTigerLog.0000000003 new file mode 100644 index 0000000..2b316b3 Binary files /dev/null and b/server/mongo_db_data_container/journal/WiredTigerLog.0000000003 differ diff --git a/server/mongo_db_data_container/journal/WiredTigerPreplog.0000000001 b/server/mongo_db_data_container/journal/WiredTigerPreplog.0000000001 new file mode 100644 index 0000000..af27d83 Binary files /dev/null and b/server/mongo_db_data_container/journal/WiredTigerPreplog.0000000001 differ diff --git a/server/mongo_db_data_container/journal/WiredTigerPreplog.0000000002 b/server/mongo_db_data_container/journal/WiredTigerPreplog.0000000002 new file mode 100644 index 0000000..af27d83 Binary files /dev/null and b/server/mongo_db_data_container/journal/WiredTigerPreplog.0000000002 differ diff --git a/server/mongo_db_data_container/mongod.lock b/server/mongo_db_data_container/mongod.lock new file mode 100644 index 0000000..e69de29 diff --git a/server/mongo_db_data_container/sizeStorer.wt b/server/mongo_db_data_container/sizeStorer.wt new file mode 100644 index 0000000..79b6140 Binary files /dev/null and b/server/mongo_db_data_container/sizeStorer.wt differ diff --git a/server/mongo_db_data_container/storage.bson b/server/mongo_db_data_container/storage.bson new file mode 100644 index 0000000..276b694 Binary files /dev/null and b/server/mongo_db_data_container/storage.bson differ diff --git a/server/requirements.txt b/server/requirements.txt new file mode 100644 index 0000000..1ab0bf7 --- /dev/null +++ b/server/requirements.txt @@ -0,0 +1,11 @@ +Flask_Cors==3.0.7 +Werkzeug==0.14.1 +passlib==1.7.1 +requests==2.24.0 +httplib2==0.12.1 +Flask==1.0.2 +python_dateutil==2.8.0 +pymongo==3.11.0 +pandas==1.1.3 +notebook==6.1.5 +itsdangerous==2.0.1 \ No newline at end of file diff --git a/server/test.py b/server/test.py index 563e246..de95429 100644 --- a/server/test.py +++ b/server/test.py @@ -1,10 +1,21 @@ +import game_analytics import requests + def test_post_data(): - url = 'http://localhost:5000/upload_data' + url = 'http://34.242.150.74/upload_data' payload = {"completion_time": 2000, "level": 7 - } + } r = requests.post(url, json=payload) print(r) -test_post_data() +def test_get_data(): + #game_analytics.connect_to_database_outside_docker() + print("Connecting to database in test_get_data") + game_analytics.connect_to_database() + + df = game_analytics.get_dataframe() + print(df) + +test_post_data() +test_get_data() \ No newline at end of file