<commit_before>﻿/*
  Copyright 2016 TUGraz, http://www.tugraz.at/
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  This project has received funding from the European Union’s Horizon
  2020 research and innovation programme under grant agreement No 644187.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  
  This software has been created in the context of the EU-funded RAGE project.
  Realising and Applied Gaming Eco-System (RAGE), Grant agreement No 644187, 
  http://rageproject.eu/

  Development was done by Cognitive Science Section (CSS) 
  at Knowledge Technologies Institute (KTI)at Graz University of Technology (TUGraz).
  http://kti.tugraz.at/css/

  Created by: <NAME>, TUGraz <<EMAIL>>
*/


using AssetManagerPackage;
using AssetPackage;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace PlayerProfilingAssetNameSpace
{
    /// <summary>
    /// Singelton Class for handling PlayerProfilingAsset actions.
    /// </summary>
    class PlayerProfilerHandler
    {

        #region Fields

        /// <summary>
        /// Instance of the PlayerProfilingAsset
        /// </summary>
        internal PlayerProfilingAsset playerProfilingAsset = null;

        /// <summary>
        /// Dictionary holding group-evaluation results after the evaluation of the questionnaire
        /// </summary>
        internal Dictionary<string,double> questionnaireResults = null;

        /// <summary>
        /// Instance of the game storage asset
        /// </summary>
        private GameStorageClientAsset storage = null;

        #endregion Fields
        #region Constructors

        /// <summary>
        /// private PlayerProfilerHandler-ctor for Singelton-pattern 
        /// </summary>
        public PlayerProfilerHandler() { }

        #endregion Constructors
        #region Properties

        #endregion Properties
        #region InternalMethods

        /// <summary>
        /// Method returning an instance of the PlayerProfilingAsset.
        /// </summary>
        /// <returns> Instance of the PlayerProfilingAsset </returns>
        internal PlayerProfilingAsset getPPA()
        {
            return PlayerProfilingAsset.Instance;
        }

        /// <summary>
        /// Method for storing Questionnaire data as html in a File.
        /// </summary>
        /// 
        /// <param name="qd"> Questionnaire data to store. </param>
        /// <param name="fileId"> String containing the file identification. </param>
        internal void writeQuestionnaireDataToHTMLFile(QuestionnaireData qd, String fileId)
        {
            IDataStorage ids = (IDataStorage)AssetManager.Instance.Bridge;
            if (ids != null)
            {
                loggingPPA("Storing Questionnaire data to HTML File.");
                //testid given from program!
                ids.Save(fileId, qd.toHTMLString("testid"));
            }
            else
                loggingPPA("No IDataStorage - Bridge implemented!", Severity.Warning);
        }

        /// <summary>
        /// Method for returning QuestionnaireData.
        /// </summary>
        /// <returns> QuestionnaireData - datastructure </returns>
        internal QuestionnaireData getQuestionnaireData()
        {
            string fileId = ((PlayerProfilingAssetSettings) getPPA().Settings).QuestionnaireDataXMLFileId;

            IDataStorage ids = (IDataStorage)AssetManager.Instance.Bridge;
            if (ids != null)
            {
                if (!ids.Exists(fileId))
                {
                    loggingPPA("File " + fileId + " not found for loading QuestionnaireData.", Severity.Error);
                    throw new Exception("EXCEPTION: File " + fileId + " not found for loading QuestionnaireData.");
                }

                loggingPPA("Loading QuestionnaireData from File.");
                return (this.getQuestionnaireDataFromXmlString(ids.Load(fileId)));
            }
            else
            {
                loggingPPA("IDataStorage bridge absent for requested local loading method of the QuestionnaireData.", Severity.Error);
                throw new Exception("EXCEPTION: IDataStorage bridge absent for requested local loading method of the QuestionnaireData.");
            }

        }

        /// <summary>
        /// gets the questionnaire data und converts it to a html - string
        /// </summary>
        /// <returns> HTML representation of the questionnaire data. </returns>
        internal string getHTMLQuestionnaire()
        {
            string htmlFileId = ((PlayerProfilingAssetSettings)getPPA().Settings).HTMLQuestionnaireFileId;
            this.writeQuestionnaireDataToHTMLFile(getQuestionnaireData(), htmlFileId);<commit_msg>removed Bridge access via AssetManager<commit_after>﻿/*
  Copyright 2016 TUGraz, http://www.tugraz.at/
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  This project has received funding from the European Union’s Horizon
  2020 research and innovation programme under grant agreement No 644187.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  
  This software has been created in the context of the EU-funded RAGE project.
  Realising and Applied Gaming Eco-System (RAGE), Grant agreement No 644187, 
  http://rageproject.eu/

  Development was done by Cognitive Science Section (CSS) 
  at Knowledge Technologies Institute (KTI)at Graz University of Technology (TUGraz).
  http://kti.tugraz.at/css/

  Created by: <NAME>, TUGraz <<EMAIL>>
*/


using AssetManagerPackage;
using AssetPackage;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace PlayerProfilingAssetNameSpace
{
    /// <summary>
    /// Singelton Class for handling PlayerProfilingAsset actions.
    /// </summary>
    class PlayerProfilerHandler
    {

        #region Fields

        /// <summary>
        /// Instance of the PlayerProfilingAsset
        /// </summary>
        internal PlayerProfilingAsset playerProfilingAsset = null;

        /// <summary>
        /// Dictionary holding group-evaluation results after the evaluation of the questionnaire
        /// </summary>
        internal Dictionary<string,double> questionnaireResults = null;

        /// <summary>
        /// Instance of the game storage asset
        /// </summary>
        private GameStorageClientAsset storage = null;

        #endregion Fields
        #region Constructors

        /// <summary>
        /// private PlayerProfilerHandler-ctor for Singelton-pattern 
        /// </summary>
        public PlayerProfilerHandler() { }

        #endregion Constructors
        #region Properties

        #endregion Properties
        #region InternalMethods

        /// <summary>
        /// Method returning an instance of the PlayerProfilingAsset.
        /// </summary>
        /// <returns> Instance of the PlayerProfilingAsset </returns>
        internal PlayerProfilingAsset getPPA()
        {
            return PlayerProfilingAsset.Instance;
        }

        /// <summary>
        /// Method for storing Questionnaire data as html in a File.
        /// </summary>
        /// 
        /// <param name="qd"> Questionnaire data to store. </param>
        /// <param name="fileId"> String containing the file identification. </param>
        internal void writeQuestionnaireDataToHTMLFile(QuestionnaireData qd, String fileId)
        {
            IDataStorage ids = PlayerProfilingAsset.Instance.getInterfaceFromAsset<IDataStorage>();
            if (ids != null)
            {
                loggingPPA("Storing Questionnaire data to HTML File.");
                //testid given from program!
                ids.Save(fileId, qd.toHTMLString("testid"));
            }
            else
                loggingPPA("No IDataStorage - Bridge implemented!", Severity.Warning);
        }

        /// <summary>
        /// Method for returning QuestionnaireData.
        /// </summary>
        /// <returns> QuestionnaireData - datastructure </returns>
        internal QuestionnaireData getQuestionnaireData()
        {
            string fileId = ((PlayerProfilingAssetSettings) getPPA().Settings).QuestionnaireDataXMLFileId;
            
            IDataStorage ids = PlayerProfilingAsset.Instance.getInterfaceFromAsset<IDataStorage>();
            if (ids != null)
            {
                if (!ids.Exists(fileId))
                {
                    loggingPPA("File " + fileId + " not found for loading QuestionnaireData.", Severity.Error);
                    throw new Exception("EXCEPTION: File " + fileId + " not found for loading QuestionnaireData.");
                }

                loggingPPA("Loading QuestionnaireData from File.");
                return (this.getQuestionnaireDataFromXmlString(ids.Load(fileId)));
            }
            else
            {
                loggingPPA("IDataStorage bridge absent for requested local loading method of the QuestionnaireData.", Severity.Error);
                throw new Exception("EXCEPTION: IDataStorage bridge absent for requested local loading method of the QuestionnaireData.");
            }

        }

        /// <summary>
        /// gets the questionnaire data und converts it to a html - string
        /// </summary>
        /// <returns> HTML representation of the questionnaire data. </returns>
        internal string getHTMLQuestionnaire()
        {
            string htmlFileId = ((PlayerProfilingAssetSettings)getPPA().Settings).HTMLQuestionnaireFileId;
            this.writeQuestionnaireDataToHTMLFile(getQuestionnaireData(), htmlFileId);
{'fraction_non_alphanumeric': 0.08700597099800966, 'fraction_numerical': 0.004549331816889394, 'mean_word_length': 2.2699101332506975, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1886491', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2466, 'n_words': 841}