Small Business
Home
VoteRank
Our Products
Contact Us
Our Location

Add your logo here

Welcome to our web site!

On this home page, we'll introduce our business and highlight important areas on our site. Here is an example of a style we may use.

using System; using System.Collections.Generic; using System.Text; using EPolBase; using EXCommon; using EPolTest; //###9.1 namespace EPolClient { ///--------------------------------------------------------------------------------------------------------------------------------------------------- ///

/// Summary description for Class1. /// ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CMemeRankVoteInputArray : CVoteInputArray { public CMemeRankVoteInputArray() { m_sErrorBuilder = new StringBuilder(); m_oMemeCompareArray = new List(); } List m_oMemeCompareArray; public override string sError { get { return m_sErrorBuilder.ToString(); } } StringBuilder m_sErrorBuilder; static SIdentifierIndex m_sInputDataRecordInstance = new SIdentifierIndex(-77); public override SIdentifierIndex iInputDataRecordInstance { get { return m_sInputDataRecordInstance; } } public override P dIsChoicePreferTo(SChoiceIndex iSubMeme1, SChoiceIndex iSubMeme2, out ENExecution dExecutionParameter) { if (_bIsChoicePreferTo(iSubMeme1, iSubMeme2, out dExecutionParameter)) { return P.TRUE; } else if (_bIsChoicePreferTo(iSubMeme2, iSubMeme1, out dExecutionParameter)) { return P.FALSE; } dExecutionParameter = ENExecution.NOT_USED; return P.UNKNOWN; } internal override string sDump() { string sOutput = ""; for(int i=0; i < m_oMemeCompareArray.Count; i++) { sOutput += m_oMemeCompareArray[i].sDump() + "\n"; } return sOutput; } protected bool _bIsChoicePreferTo(SChoiceIndex iSubMeme1, SChoiceIndex iSubMeme2, out ENExecution dExecutionParameter) { m_sErrorBuilder = new StringBuilder(); for (int i = 0; i < m_oMemeCompareArray.Count; i++) { SMemeCompare oMemeCompare = (SMemeCompare)m_oMemeCompareArray[i]; if (oMemeCompare.dSubIndex1 == iSubMeme1) { if (oMemeCompare.dSubIndex2 == iSubMeme2) { dExecutionParameter = oMemeCompare.dExecutionFeature; return true; } else { m_sErrorBuilder.AppendLine(oMemeCompare.sDump()); ENExecution dPreviousExecutionParameter; if (_bIsChoicePreferTo(oMemeCompare.dSubIndex2, iSubMeme2, out dPreviousExecutionParameter)) { dExecutionParameter = dExecutionFeatureAnd(oMemeCompare.dExecutionFeature, dPreviousExecutionParameter); return true; } } } } dExecutionParameter = ENExecution.NOT_USED; return false; } protected override ec _dAddChoice(SChoiceIndex iSubMeme1, SChoiceIndex iSubMeme2, ENExecution dExecutionParameter) { ENExecution dCurrentExecutionParameter; P dPreference = dIsChoicePreferTo(iSubMeme1, iSubMeme2, out dCurrentExecutionParameter); if (dPreference == P.TRUE) { m_sErrorBuilder.AppendLine(iSubMeme1.ToString() + " is already prefered to " + iSubMeme2.ToString()); if (dExecutionParameter != dCurrentExecutionParameter) { m_sErrorBuilder.AppendLine(" The current execution parameter " + dCurrentExecutionParameter + " is different of your execution parameter " + dExecutionParameter); return ec.ST_VOTE_PREFERENCE_ALREADY_RECORDED_MISMATCH_EXECUTION_PARAMETER; } return ec.ST_VOTE_PREFERENCE_ALREADY_RECORDED; } else if (dPreference == P.FALSE) { m_sErrorBuilder.AppendLine(iSubMeme1.ToString() + " is currently not prefered to " + iSubMeme2.ToString()); return ec.ST_VOTE_CAN_NOT_ADD_PAIR_OF_CHOICE_DUE_OPPOSITE_CYCLE; } else { SMemeCompare oNewMemeCompare = new SMemeCompare(); oNewMemeCompare.dSubIndex1 = iSubMeme1; oNewMemeCompare.dSubIndex2 = iSubMeme2; oNewMemeCompare.dExecutionFeature = dExecutionParameter; m_oMemeCompareArray.Add(oNewMemeCompare); return ec.ST_SUCCEED; } } public override ec dLoad(SProfileIndex dProfileIndex, SIdentifierIndex dMemeId, byte[] dBallotBinary) { SMemeCompare[] oMemeCompareArray = (SMemeCompare[])Deserialize(dBallotBinary); for (int i = 0; i < oMemeCompareArray.Length; i++) { m_oMemeCompareArray.Add(oMemeCompareArray[i]); } return ec.ST_SUCCEED; } public override byte[] GetSerializedBinary() { return GetSerializedValue(m_oMemeCompareArray); } public override int Length { get { return m_oMemeCompareArray.Count; } } public SMemeCompare[] ChoiceCompareArray { get { return (SMemeCompare[])m_oMemeCompareArray.ToArray(); } } public SMemeCompare GetMemeCompareArray(int i) { return (SMemeCompare)m_oMemeCompareArray[i]; } public struct SMemeCompare { /* public static SMemeIndex iRegister() { return CMemeManager.Instance().iAddCodeInstance(P.INPUT_RECORD_CSHARP, new CCSharpCodeMeme(new SMemeCompare())); }*/ public void vSet(P dComparator) { switch (dComparator) { case P.EXCLUSIVE_EXECUTION: m_dExecutionFeature = ENExecution.Exclusive; break; case P.DEPENDANT_EXECUTION: m_dExecutionFeature = ENExecution.DoneOnlyIfOtherDone; break; case P.INDEPENDANT_EXECUTION: default: m_dExecutionFeature = ENExecution.Independant; break; } } public void vSet(object[] oObjectArray) { m_dSubIndex1 = new SChoiceIndex(Convert.ToInt32(oObjectArray[0])); m_dSubIndex2 = new SChoiceIndex(Convert.ToInt32(oObjectArray[1])); P dComparator = (P)Convert.ToInt32(oObjectArray[2]); vSet(dComparator); // EPAssert(m_dMemeIndex != m_dReferenceIndex, "You can not compare a meme with himself"); } public SChoiceIndex dSubIndex1 { get { return m_dSubIndex1; } set { m_dSubIndex1 = value; } } public SChoiceIndex dSubIndex2 { get { return m_dSubIndex2; } set { m_dSubIndex2 = value; } } internal string sDump() { return m_dExecutionFeature.ToString() + "(" + m_dSubIndex1 + ">" + m_dSubIndex2 + ")"; } public ENExecution dExecutionFeature { get { return m_dExecutionFeature; } set { m_dExecutionFeature = value; } } private SChoiceIndex m_dSubIndex1; private SChoiceIndex m_dSubIndex2; private ENExecution m_dExecutionFeature; } } public class CBottomCountArray : CVoteResultArray { public CBottomCountArray(SBottomCount[] oIndexMemeRankList) { m_oIndexMemeRankList = oIndexMemeRankList; } SBottomCount[] m_oIndexMemeRankList; public override int dCount { get { return m_oIndexMemeRankList.Length; } } public override CEPBase.SChoiceIndex iGetChoice(int i) { return m_oIndexMemeRankList[i].dMemeSubIndex; } public override double dGetCountToRank(int i) { return m_oIndexMemeRankList[i].dbCount; } public override string sGetClassementCriteriaName { get { return "count_neg"; } } internal override string sDump() { string sOutput = ""; for(int i=0; i < m_oIndexMemeRankList.Length; i++) { sOutput += m_oIndexMemeRankList[i].sDump() + "\n"; } return sOutput; } public struct SBottomCount { public CEPBase.SChoiceIndex dMemeSubIndex; public double dbCount; internal string sDump() { return dMemeSubIndex.ToString() + "(" + dbCount + ")"; } } /* public override SChoiceIndex iGetChoiceVoted { get { if (dbCount == 0) return SChoiceIndex.NOT_USED; return m_oIndexMemeRankList[0].dMemeSubIndex; } }*/ public override bool bIsWinnerOn(int i1, int i2) { return i1 < i2; } public override byte[] GetSerializeResult { get { return CEPBase.GetSerializedValue(m_oIndexMemeRankList); } } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CRankVoting : CVoting { public CRankVoting(CVoteRightList oVoteRightList) : base(new CProfileVotingList(oVoteRightList), oVoteRightList, new CChoiceSortedList()) { } public override CVoteInputArray oCreate() { return new CMemeRankVoteInputArray(); } public override void vSetProfileAt(SProfileIndex iProfileIndex, CVoteInputArray oVoteInputArray) { // SProfileIndex dProfileIndex = m_oVoteRightArray[i].iProfileIndex; // CMemeRankVoteInputArray.SMemeCompare[] oMemeCompareArray = ((CMemeRankVoteInputArray)oVoteInputArray).ChoiceCompareArray; if (oVoteInputArray != null) { CMemeRankVoteInputArray oMemeCompareInputArray = (CMemeRankVoteInputArray)oVoteInputArray; CProfileRankVoting oProfileRankVoting = new CProfileRankVoting(); CMemeRankVoteInputArray.SMemeCompare[] oMemeCompareArray = oMemeCompareInputArray.ChoiceCompareArray; for (int j = 0; j < oMemeCompareInputArray.Length; j++) { CTrace.i().vWriteLn(ENMessage.Vote, " oMemeCompare[j] = " + oMemeCompareArray[j].sDump()); m_oChoiceIndexList.Add(oMemeCompareArray[j].dSubIndex1, null); m_oChoiceIndexList.Add(oMemeCompareArray[j].dSubIndex2, null); } oProfileRankVoting.vAdd(oMemeCompareInputArray); m_oProfileVotingList.vAdd(iProfileIndex, oProfileRankVoting); } } //dGetExecutionRelation(int[] dMemeArray, int dMemeIndex) public override void vVote(out CVoteResultArray oMemeRankResultList, ref CTraceReport oTraceReport) { CProfileVotingList oRankVotingList = m_oProfileVotingList; CBottomCountArray.SBottomCount[] oIndexMemeRankList = new CBottomCountArray.SBottomCount[m_oChoiceIndexList.Count]; int dMemeRankIndex = 0; while (m_oChoiceIndexList.Count > 0) { CBottomCountArray.SBottomCount[] oMemeCountArray = new CBottomCountArray.SBottomCount[m_oChoiceIndexList.Count]; CListReport oDetailProfileReport = new CListReport(3); oDetailProfileReport.Active = oTraceReport.Active; oDetailProfileReport.vSetTitle("Bottom popularity detail report meme total=" + oRankVotingList.ProfileCount); oDetailProfileReport.vSetHeader("Bottom_Meme", "Profile", "Vote_right"); CListReport oDetailReport = new CListReport(2); oDetailReport.Active = oTraceReport.Active; oDetailReport.vSetTitle("Bottom popularity detail report meme total=" + oRankVotingList.ProfileCount); oDetailReport.vSetHeader("Meme", "Bottom_count"); for (int i = 0; i < m_oChoiceIndexList.Count; i++) { oMemeCountArray[i].dMemeSubIndex = m_oChoiceIndexList.GetKey(i); CTrace.i().vWriteLn(ENMessage.Vote, " choice " + oMemeCountArray[i].dMemeSubIndex); oMemeCountArray[i].dbCount = 0; for (SProfileRankIndex k = SProfileRankIndex.CreateInitValue(oRankVotingList); k < oRankVotingList.ProfileCount; k++) { CTrace.i().vWriteLn(ENMessage.Vote, " oRankVotingList = " + oRankVotingList.sDump()); SProfileIndex dProfileIndex = k.ProfileIndex; CProfileRankVoting oProfileRankVoting = (CProfileRankVoting)oRankVotingList.GetProfileVoting(k); if ( oProfileRankVoting.bIsAtPopularityBottom(oMemeCountArray[i].dMemeSubIndex)) { oMemeCountArray[i].dbCount += m_oVoteRightList[k].dbVoteCoefficient; oDetailProfileReport.vAdd(CReport.CHOICE + oMemeCountArray[i].dMemeSubIndex, m_oVoteRightList.sGetProfileDisplayName(k), m_oVoteRightList[k]); } } CTrace.i().vWriteLn(ENMessage.Vote, "count " + oMemeCountArray[i].dbCount); oDetailReport.vAdd(CReport.CHOICE + oMemeCountArray[i].dMemeSubIndex, oMemeCountArray[i].dbCount); } oTraceReport.vAdd(oDetailProfileReport); oTraceReport.vAdd(oDetailReport); if (oMemeCountArray.Length >= 1) { CBottomCountArray.SBottomCount oBottomCountMax = oMemeCountArray[0]; for (int j = 1; j < oMemeCountArray.Length; j++) { if (oBottomCountMax.dbCount < oMemeCountArray[j].dbCount) { oBottomCountMax = oMemeCountArray[j]; } } oIndexMemeRankList[dMemeRankIndex] = oBottomCountMax; oTraceReport.vAddLine(dMemeRankIndex + ":Remove meme " + CReport.CHOICE + oBottomCountMax.dMemeSubIndex + " Count=" + oBottomCountMax.dbCount); dMemeRankIndex++; oRankVotingList.vRemove(oBottomCountMax.dMemeSubIndex); // vRemove(ref oRankVotingList, oBottomCountMax.dMemeSubIndex); m_oChoiceIndexList.Remove(oBottomCountMax.dMemeSubIndex); } } oMemeRankResultList = new CBottomCountArray(oIndexMemeRankList); } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CProfileRankVoting : CProfileVoting { public CProfileRankVoting() : base() { m_oChoiceList = new CChoiceSortedList(); } CChoiceSortedList m_oChoiceList; public void vAdd(CVoteInputArray oMemeCompareInputArray) { CMemeRankVoteInputArray.SMemeCompare[] oMemeCompareArray = ((CMemeRankVoteInputArray)oMemeCompareInputArray).ChoiceCompareArray; for (int i = 0; i < oMemeCompareArray.Length; i++) { vAdd(oMemeCompareArray[i]); } } protected void vAdd(CMemeRankVoteInputArray.SMemeCompare oMemeCompare) { m_oChoiceList.Add(oMemeCompare.dSubIndex1, new CChoiceLink(oMemeCompare.dSubIndex2, oMemeCompare.dExecutionFeature)); if (m_oChoiceList.Contains(oMemeCompare.dSubIndex2)) { CChoiceLink oMemeLink = (CChoiceLink)m_oChoiceList[oMemeCompare.dSubIndex2]; oMemeLink.vAdd(oMemeCompare.dSubIndex1); m_oChoiceList.Remove(oMemeCompare.dSubIndex2); m_oChoiceList.Add(oMemeCompare.dSubIndex2, oMemeLink); } } public bool bIsAtPopularityBottom(SChoiceIndex dIndex) { return m_oChoiceList[dIndex] == null; } public override void vRemove(SChoiceIndex dIndex) { CChoiceLink oMemeLink = (CChoiceLink)m_oChoiceList[dIndex]; if (oMemeLink != null) { for (int i = 0; i < oMemeLink.MostPopularChoiceCount; i++) { SChoiceIndex dMostPopularMemeIndex = (SChoiceIndex)oMemeLink.GetMostPopularChoiceByIndex(i); CChoiceLink oMemeSupLink = ((CChoiceLink)m_oChoiceList[dMostPopularMemeIndex]); if (oMemeSupLink != null) { oMemeSupLink.m_dLessPopularChoiceIndex = oMemeLink.m_dLessPopularChoiceIndex; m_oChoiceList.Remove(dMostPopularMemeIndex); m_oChoiceList.Add(dMostPopularMemeIndex, oMemeSupLink); } } } } public ENExecution dGetExecutionFeatureIndex(SChoiceIndex dMemeIndex1, SChoiceIndex dMemeIndex2) { SChoiceIndex _dMemeIndex1 = dMemeIndex1; while (true) { CChoiceLink oMeme1 = ((CChoiceLink)m_oChoiceList[_dMemeIndex1]); if (oMeme1 == null) { return ENExecution.Independant; } if (dMemeIndex2 == oMeme1.m_dLessPopularChoiceIndex) { return oMeme1.m_dExecutionFeatureIndex; } else { _dMemeIndex1 = oMeme1.m_dLessPopularChoiceIndex; } } } //------- public class CChoiceLink { public CChoiceLink(SChoiceIndex _dLessPopularIndex, ENExecution _dExecutionFeatureIndex) { m_oMostPopularChoiceArrayList = new List(); m_dLessPopularChoiceIndex = _dLessPopularIndex; m_dExecutionFeatureIndex = _dExecutionFeatureIndex; } public void vAdd(SChoiceIndex dMemeSupIndex) { m_oMostPopularChoiceArrayList.Add(dMemeSupIndex.dIndex); } public SChoiceIndex m_dLessPopularChoiceIndex; public ENExecution m_dExecutionFeatureIndex; List m_oMostPopularChoiceArrayList; public int MostPopularChoiceCount { get { return m_oMostPopularChoiceArrayList.Count; } } public SChoiceIndex GetMostPopularChoiceByIndex(int i) { return new SChoiceIndex(m_oMostPopularChoiceArrayList[i]); } } //------- } ///--------------------------------------------------------------------------------------------------------------------------------------------------- ///--------------------------------------------------------------------------------------------------------------------------------------------------- ///--------------------------------------------------------------------------------------------------------------------------------------------------- ///--------------------------------------------------------------------------------------------------------------------------------------------------- public abstract class CGradeVoting : CVoting { public CGradeVoting(CVoteRightList oVoteRightList) : base(new CProfileVotingList(oVoteRightList), oVoteRightList, new CChoiceSortedList()) { } public static SVoteGrade[] ToVoteGrade(List oArray) { SVoteGrade[] oVoteGradeArray = new SVoteGrade[oArray.Count]; for (int i = 0; i < oArray.Count; i++) { object[] oObjArray = (object[])oArray[i]; oVoteGradeArray[i].iProfileIndex = new SProfileIndex(Convert.ToInt32(oObjArray[0])); oVoteGradeArray[i].iMemeIndex = new SChoiceIndex(Convert.ToInt32(oObjArray[1])); oVoteGradeArray[i].dGrade = Convert.ToInt32(oObjArray[2]); } return oVoteGradeArray; } protected void vAdd(SProfileIndex iProfileIndex, SVoteGrade[] oVoteGradeArray) { CProfileGradeVoting oProfileGradeVoting = new CProfileGradeVoting(); for (int j = 0; j < oVoteGradeArray.Length; j++) { if (oVoteGradeArray[j].iProfileIndex == iProfileIndex) { m_oChoiceIndexList.Add(oVoteGradeArray[j].iMemeIndex, null); oProfileGradeVoting.vAdd(new CProfileGradeVoting.SGrade(oVoteGradeArray[j].iMemeIndex, oVoteGradeArray[j].dGrade)); } } m_oProfileVotingList.vAdd(iProfileIndex,oProfileGradeVoting); } public void vAdd(SVoteGrade[] oVoteGradeArray) { for (SProfileRankIndex i = SProfileRankIndex.CreateInitValue(m_oProfileVotingList); i < m_oProfileVotingList.ProfileCount; i++) { vAdd(i.ProfileIndex, oVoteGradeArray); } } public class CVoteGradeResultArray : CVoteResultArray { public CVoteGradeResultArray(SVoteGradeResult[] oVoteGradeResultArray) { m_oVoteGradeResultArray = oVoteGradeResultArray; } SVoteGradeResult[] m_oVoteGradeResultArray; public override int dCount { get { return m_oVoteGradeResultArray.Length; } } public override SChoiceIndex iGetChoice(int i) { return m_oVoteGradeResultArray[i].dChoiceIndex; } public override string sGetClassementCriteriaName { get { return "avg_grade"; } } public override double dGetCountToRank(int i) { return m_oVoteGradeResultArray[i].dbAvg; } public override byte[] GetSerializeResult { get { return GetSerializedValue(m_oVoteGradeResultArray); } } public override bool bIsWinnerOn(int i1, int i2) { return m_oVoteGradeResultArray[i1].dSumGrade > m_oVoteGradeResultArray[i2].dSumGrade; } internal override string sDump() { string sOutput = ""; for(int i=0; i < m_oVoteGradeResultArray.Length;i++) { sOutput += m_oVoteGradeResultArray[i].sDump() + "\n"; } return sOutput; } } public struct SVoteGradeResult { public SVoteGradeResult(SChoiceIndex _dChoiceIndex) { dChoiceIndex = _dChoiceIndex; dSumGrade = dbCount = 0; } public SChoiceIndex dChoiceIndex; public double dSumGrade; public double dbCount; public double dbAvg { get { return dSumGrade / dbCount; } } public static SVoteGradeResult NOT_USED = new SVoteGradeResult(CEPBase.SChoiceIndex.NOT_USED); internal string sDump() { string sOutput = "dChoice= " + dChoiceIndex.ToString(); sOutput += "| dbAvg(" + dbAvg + ")=" + dSumGrade + "/" + dbCount; return sOutput; } } static public SVoteGradeResult dGetWinner(SVoteGradeResult[] oVoteGradeResultArray) { if (oVoteGradeResultArray.Length == 0) return SVoteGradeResult.NOT_USED; SVoteGradeResult oSVoteGradeResult = oVoteGradeResultArray[0]; for (int i = 0; i < oVoteGradeResultArray.Length; i++) { if (oVoteGradeResultArray[i].dbAvg > oSVoteGradeResult.dbAvg) { oSVoteGradeResult = oVoteGradeResultArray[i]; } } return oSVoteGradeResult; } public double dBallotCount { get { double dBallotCount = 0; for (SProfileRankIndex i = SProfileRankIndex.CreateInitValue(m_oProfileVotingList); i < m_oProfileVotingList.ProfileCount; i++) { CProfileGradeVoting oProfileGradeVoting = (CProfileGradeVoting)m_oProfileVotingList.GetProfileVoting(i.ProfileIndex); dBallotCount += m_oVoteRightList[i].dbVoteCoefficient; } return dBallotCount; } } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CGradeAverageVoting : CGradeVoting { public CGradeAverageVoting(ENPonderation enPonderation, CVoteRightList oVoteRightArrayList) : base(oVoteRightArrayList) { m_enPonderation = enPonderation; } ENPonderation m_enPonderation; public override CVoteInputArray oCreate() { return null; } public enum ENPonderation { Normal, Ponderate, Normalized } public override void vSetProfileAt(SProfileIndex iProfileRankIndex, CVoteInputArray oMemeCompareArray) { EPAssert(false, "Not implemented"); } public override void vVote(out CVoteResultArray oVoteResultArray, ref CTraceReport oTraceReport) { SVoteGradeResult[] oVoteGradeResultArray = new SVoteGradeResult[m_oChoiceIndexList.Count]; CListReport oDetailReport = new CListReport(4); oDetailReport.Active = oTraceReport.Active; oDetailReport.vSetTitle("Detail vote by grade"); oDetailReport.vSetHeader("Meme", "Profile", "Vote right", "Grade"); for (int i = 0; i < m_oChoiceIndexList.Count; i++) { SChoiceIndex iChoiceIndex = m_oChoiceIndexList.GetKey(i); for (SProfileRankIndex j = SProfileRankIndex.CreateInitValue(m_oProfileVotingList); j < m_oProfileVotingList.ProfileCount; j++) { SProfileIndex dProfileIndex = j.ProfileIndex; CProfileGradeVoting oProfileGradeVoting = (CProfileGradeVoting)m_oProfileVotingList.GetProfileVoting(dProfileIndex); if (oProfileGradeVoting != null) { double dbGrade; if (m_enPonderation == ENPonderation.Ponderate) { dbGrade = oProfileGradeVoting.dbGetPonderation(iChoiceIndex); } else if (m_enPonderation == ENPonderation.Normalized) { dbGrade = oProfileGradeVoting.dbGetNormalizedGrade(iChoiceIndex); } else { dbGrade = oProfileGradeVoting.dbGetGrade(iChoiceIndex); } if (bIsUsed(dbGrade)) { oVoteGradeResultArray[i].dbCount += m_oVoteRightList[j].dbVoteCoefficient; oVoteGradeResultArray[i].dSumGrade += m_oVoteRightList[j].dbVoteCoefficient * dbGrade; oDetailReport.vAdd(CReport.CHOICE + iChoiceIndex, CReport.MEMBER + dProfileIndex, m_oVoteRightList[j].dbVoteCoefficient, dbGrade); } } } i++; } oTraceReport.vAdd(oDetailReport); CListReport oVoteGradeReport = new CListReport(2); oVoteGradeReport.Active = oTraceReport.Active; oVoteGradeReport.vSetTitle("Result vote"); oVoteGradeReport.vSetHeader("Meme", "Average Grade"); for (int j = 0; j < oVoteGradeResultArray.Length; j++) { oVoteGradeReport.vAdd(CReport.CHOICE + oVoteGradeResultArray[j].dChoiceIndex, oVoteGradeResultArray[j].dbAvg); } oTraceReport.vAdd(oVoteGradeReport); //SVoteGradeResult oVoteResultArray = new CVoteGradeResultArray(oVoteGradeResultArray); } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CGradeRankVoting : CGradeVoting { public CGradeRankVoting(CVoteRightList oVoteRightList) : base(oVoteRightList) { } public override void vSetProfileAt(SProfileIndex iProfileRankIndex, CVoteInputArray oMemeCompareArray) { EPAssert(false, "Not implemented"); } public override CVoteInputArray oCreate() { return new CMemeRankVoteInputArray(); } public override void vVote(out CVoteResultArray oVoteResultArray, ref CTraceReport oTraceReport) { SVoteGradeResult[] oVoteGradeResultArray = new SVoteGradeResult[m_oChoiceIndexList.Count]; CListReport oDetailReport = new CListReport(4); oDetailReport.Active = oTraceReport.Active; oDetailReport.vSetTitle("Detail vote by grade"); oDetailReport.vSetHeader("Meme", "Profile", "Vote right", "Grade"); for (int i = 0; i < m_oChoiceIndexList.Count; i++) { SChoiceIndex dChoiceIndex = (SChoiceIndex)m_oChoiceIndexList.GetKey(i); for (SProfileRankIndex j = SProfileRankIndex.CreateInitValue(m_oProfileVotingList); j < m_oProfileVotingList.ProfileCount; j++) { SProfileIndex dProfileIndex = j.ProfileIndex; CProfileGradeVoting oProfileGradeVoting = (CProfileGradeVoting)m_oProfileVotingList.GetProfileVoting(j); if (oProfileGradeVoting != null) { double dbRank = oProfileGradeVoting.dGetRank(dChoiceIndex); if (dbRank == oProfileGradeVoting.dbCount) { dbRank = (m_oChoiceIndexList.Count - oProfileGradeVoting.dbCount) / 2 + oProfileGradeVoting.dbCount; } oVoteGradeResultArray[i].dbCount += m_oVoteRightList[j].dbVoteCoefficient; oVoteGradeResultArray[i].dSumGrade += m_oVoteRightList[j].dbVoteCoefficient * dbRank / m_oChoiceIndexList.Count; oDetailReport.vAdd(CReport.CHOICE + dChoiceIndex, CReport.MEMBER + dProfileIndex, m_oVoteRightList[j].dbVoteCoefficient, dbRank / m_oChoiceIndexList.Count); } } i++; } oTraceReport.vAdd(oDetailReport); CListReport oVoteGradeReport = new CListReport(2); oVoteGradeReport.Active = oTraceReport.Active; oVoteGradeReport.vSetTitle("Result vote"); oVoteGradeReport.vSetHeader("Meme", "Average Grade"); for (int j = 0; j < oVoteGradeResultArray.Length; j++) { oVoteGradeReport.vAdd(CReport.CHOICE + oVoteGradeResultArray[j].dChoiceIndex, oVoteGradeResultArray[j].dbAvg); } oTraceReport.vAdd(oVoteGradeReport); oVoteResultArray = new CVoteGradeResultArray(oVoteGradeResultArray); } } ///--------------------------------------------------------------------------------------------------------------------------------------------------- public class CProfileGradeVoting : CProfileVoting { public CProfileGradeVoting() : base() { m_oChoiceList = new CChoiceSortedList(); m_dSum = m_dSquareSum = 0; } public struct SGrade { public SGrade(SChoiceIndex _dIndex, double _dbGrade) { dChoiceIndex = _dIndex; dbGrade = _dbGrade; dRank = NOT_USED; } public SChoiceIndex dChoiceIndex; public double dbGrade; public int dRank; } public void vAdd(SGrade oGrade) { m_oChoiceList.Add(oGrade.dChoiceIndex, oGrade); } CChoiceSortedList m_oChoiceList; //, m_oMemeGradeRankList; public override void vRemove(SChoiceIndex dSubIndex) { m_oChoiceList.Remove(dSubIndex); } double m_dSum; double m_dSquareSum; public int dbCount { get { return m_oChoiceList.Count; } } public double dSum { get { if (m_dSum == 0) { for (int i = 0; i < m_oChoiceList.Count; i++) { m_dSum += ((SGrade)m_oChoiceList.GetByIndex(i)).dbGrade; } } return m_dSum; } } public double dAvg { get { if (m_oChoiceList.Count > 0) { return dSum / m_oChoiceList.Count; } return NOT_USED; } } public double dStd { get { if (m_dSquareSum == 0) { for (int i = 0; i < m_oChoiceList.Count; i++) { SGrade oMemGrade = (SGrade)m_oChoiceList.GetByIndex(i); double dEcard = oMemGrade.dbGrade - dAvg; m_dSquareSum += dEcard * dEcard; } } if (m_oChoiceList.Count > 1) { return Math.Sqrt(m_dSquareSum / m_oChoiceList.Count); } return NOT_USED; } } public double dbGetGrade(SChoiceIndex dChoiceIndex) { return ((SGrade)m_oChoiceList[dChoiceIndex]).dbGrade; } public double dbGetNormalizedGrade(SChoiceIndex dIndex) { double dbGrade = dbGetGrade(dIndex); if (dbGrade == NOT_USED) { return NOT_USED; } return dbNormalizedGrade(dbGrade); } public int dGetRank(SChoiceIndex dIndex) { if (m_oChoiceList.Count > 0 && IsNotUsed(((SGrade)m_oChoiceList[dIndex]).dRank)) { SortedList oMemeGradeRankList = new SortedList(); for (int i = 0; i < m_oChoiceList.Count; i++) { //SChoiceIndex iChoice = m_oChoiceList.GetKey(i); SGrade oGrade = (SGrade)m_oChoiceList.GetByIndex(i); oMemeGradeRankList.Add(oGrade.dbGrade, oGrade.dChoiceIndex); } for (int i = 0; i < oMemeGradeRankList.Count; i++) { SChoiceIndex iNewChoice = (SChoiceIndex)oMemeGradeRankList.Values[i]; SGrade oGrade = (SGrade)m_oChoiceList[iNewChoice]; oGrade.dRank = i; m_oChoiceList[iNewChoice] = oGrade; } } return m_oChoiceList.Contains(dIndex) ? ((SGrade)m_oChoiceList[dIndex]).dRank : m_oChoiceList.Count; } public double dbNormalizedGrade(double dbGrade) { return Math.Sqrt((dbGrade - dAvg) * (dbGrade - dAvg)) / m_dSquareSum; } public double dbGetPonderation(SChoiceIndex dIndex) { double dbGrade = dbGetGrade(dIndex); if (dbGrade == NOT_USED) { return NOT_USED; } return dbGrade / dSum; } } }

Here we may display a picture of this month's special:

cdgreyscale.jpg
Blank CDs: 20% off
Please get in touch to offer comments and join our mailing list for sales and specials!

You can e-mail us at:

Our Company * Any Street * Anytown * US * 01234