/****************************************************************************
 Function
    RunPhotoTransistorService
 Parameters
   ES_Event : the event to process
 Returns
   ES_Event, ES_NO_EVENT if no error ES_ERROR otherwise
****************************************************************************/
ES_Event RunPhotoTransistorService( ES_Event ThisEvent )
{
  ES_Event ReturnEvent;
  ReturnEvent.EventType = ES_NO_EVENT; // assume no errors
  
	// If we have stopped seeing pulses, it's time to evaluate whether we saw a beacon
	if ((ThisEvent.EventType == ES_TIMEOUT) && (ThisEvent.EventParam == AVERAGE_BEACONS_TIMER))
	{
		// If the beacon we were interested in had enough pulses
		if (numSamples[LastBeacon] >= NUMBER_PULSES_TO_BE_ALIGNED)
		{
			// set the last update time for the beacon
			beacons[LastBeacon].lastUpdateTime = captureInterrupt(PHOTOTRANSISTOR_INTERRUPT_PARAMATERS);
			
			// set the angle to the beacon based on the average of all pulses measured
			beacons[LastBeacon].lastEncoderAngle = CalculateAverage(LastBeacon);
			
			// Store this beacon as the last updated beacon
			LastUpdatedBeacon = LastBeacon;
			
			// Determine if we should recalculate our position and angle based on whether or not we have received 3 consecutive pulses
			if (TimeForUpdate())
			{
				ES_Event NewEvent;
				NewEvent.EventType = ES_CALCULATE_POSITION;
				PostPositionLogicService(NewEvent);
			}
			
		}
		
		// Reset stored average information
		ResetAverage();
		
		// Reallow new beacons to be recorded
		Bucketing = true;
		
		LastBeacon = NULL_BEACON;
		
		ES_Timer_StopTimer(AVERAGE_BEACONS_TIMER);
	}
	else if (ThisEvent.EventType == ES_ALIGN_TO_BUCKET)
	{
		// If we are trying to align to the bucket for a shot, 
		//  shift the way we handle interrupts
		AligningToBucket = true;
		enableCaptureInterrupt(PHOTOTRANSISTOR_INTERRUPT_PARAMATERS);
	}
	
  return ReturnEvent;
}
Esempio n. 2
0
	const mat3 CreateCovarianceMatrix(const float* points, int count, unsigned point_size)
	{
		//	find average of the vertices
		vec3 center = CalculateAverage(points, count, point_size);

		//	find covariance matrix
		mat3 res;
		res.Zerofy();

		for (int i = 0; i < count; ++i)
		{
			const vec3 v(points[i*(point_size/sizeof(float)) + 0], points[i*(point_size/sizeof(float)) + 1], points[i*(point_size/sizeof(float)) + 2]);
			res += MultTransposed((v - center), (v - center));
		}

		res /= (float)count;

		return res;
	}
void PerformanceEvaluator::CalculateRM(VecPtr vec) {
  CalculateAverage(vec);
  transform(vec->begin(),vec->end(),vec->begin(),[](const double& x) {return sqrt(x);});
}
PerformanceEvaluator::PerformanceEvaluator(){
  _performanceValueTuples["NORXE"] = make_tuple(make_shared<vector<double>>(),
                                                PerformanceFunction([=](SVref xEst,SCMref P,SVref xReal) {
                                                  return CalculateNORXE(xEst,P,xReal);
                                                  }),
                                                FinishFunction([=](VecPtr vec) {
                                                  return CalculateAverage(vec);
                                                }));
  _performanceValueTuples["FPOS"] = make_tuple(make_shared<vector<double>>(),
                                                PerformanceFunction([=](SVref xEst,SCMref P,SVref xReal) {
                                                  return CalculateFPOS(xEst,P,xReal);
                                                }),
                                                FinishFunction([=](VecPtr vec) {
                                                  return CalculateRM(vec);
                                                }));
  _performanceValueTuples["FVEL"] = make_tuple(make_shared<vector<double>>(),
                                                PerformanceFunction([=](SVref xEst,SCMref P,SVref xReal) {
                                                  return CalculateFVEL(xEst,P,xReal);
                                                }),
                                                FinishFunction([=](VecPtr vec) {
                                                  return CalculateRM(vec);
                                                }));
  _performanceValueTuples["RMSPOS"] = make_tuple(make_shared<vector<double>>(),
                                                PerformanceFunction([=](SVref xEst,SCMref P,SVref xReal) {
                                                  return Square(CalculatePOS(xEst,P,xReal));
                                                }),
                                                FinishFunction([=](VecPtr vec) {
                                                  return CalculateRM(vec);
                                                }));
  _performanceValueTuples["RMSVEL"] = make_tuple(make_shared<vector<double>>(),
                                                 PerformanceFunction([=](SVref xEst,SCMref P,SVref xReal) {
                                                   return Square(CalculateVEL(xEst,P,xReal));
                                                 }),
                                                 FinishFunction([=](VecPtr vec) {
                                                   return CalculateRM(vec);
                                                 }));
  _performanceValueTuples["RMSSPD"] = make_tuple(make_shared<vector<double>>(),
                                                 PerformanceFunction([=](SVref xEst,SCMref P,SVref xReal) {
                                                   return Square(CalculateSPD(xEst,P,xReal));
                                                 }),
                                                 FinishFunction([=](VecPtr vec) {
                                                   return CalculateRM(vec);
                                                 }));
  _performanceValueTuples["RMSCRS"] = make_tuple(make_shared<vector<double>>(),
                                                 PerformanceFunction([=](SVref xEst,SCMref P,SVref xReal) {
                                                   return Square(CalculateCRS(xEst,P,xReal));
                                                 }),
                                                 FinishFunction([=](VecPtr vec) {
                                                   return CalculateRM(vec);
                                                 }));
  _performanceValueTuples["NEES"] = make_tuple(make_shared<vector<double>>(),
                                                 PerformanceFunction([=](SVref xEst,SCMref P,SVref xReal) {
                                                   return CalculateNEES(xEst,P,xReal);
                                                 }),
                                                 FinishFunction([=](VecPtr vec) {
                                                   return CalculateAverage(vec);
                                                 }));
  _performanceValueTuples["MOD2PR"] = make_tuple(make_shared<vector<double>>(),
                                               PerformanceFunction([](SVref xEst,SCMref P,SVref xReal) {
                                                 return -99999.99999;//this will never happen
                                               }),
                                               FinishFunction([=](VecPtr vec) {
                                                 return CalculateAverage(vec);
                                               }));
  _performanceValueTuples["RAWRMSPOS"] = make_tuple(make_shared<vector<double>>(),
                                                 PerformanceFunction([=](SVref xEst,SCMref P,SVref xReal) {
                                                   return Square(CalculatePOS(xEst,P,xReal));
                                                 }),
                                                 FinishFunction([=](VecPtr vec) {
                                                   return CalculateRM(vec);
                                                 }));

}
Esempio n. 5
0
int main(int argc, char **argv)
{
   osFile fh;
   uint32_t total,areas,totaldupes;
   time_t firsttime,t;
   uint32_t DayStatsWritten;
   char buf[200],date[30],date2[30];
   struct DiskAreaStats dastat;
   struct DiskNodeStats dnstat;
   struct StatsNode *sn;
   struct NodeStatsNode *nsn;
   struct jbList StatsList;
   struct jbList NodesList;
   uint32_t c,num,tot;
   uint16_t total8days[8];
   char sortmode;
   struct tm *tp;
   char *monthnames[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","???"};

   signal(SIGINT,breakfunc);
         
   if(!osInit())
      exit(OS_EXIT_ERROR);

   if(argc > 1 &&
	  (strcmp(argv[1],"?")==0      ||
		strcmp(argv[1],"-h")==0     ||
		strcmp(argv[1],"--help")==0 ||
		strcmp(argv[1],"help")==0 ||
		strcmp(argv[1],"/h")==0     ||
		strcmp(argv[1],"/?")==0 ))
   {
      printargs(args);
      osEnd();
      exit(OS_EXIT_OK);
   }

   if(!parseargs(args,argc,argv))
   {
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   sortmode='a';
   
   if(args[ARG_SORT].data)
      sortmode=tolower(((char *)args[ARG_SORT].data)[0]);
      
   if(!strchr("amtdlu",sortmode))
   {
      printf("Unknown sort mode %c\n",sortmode);
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   if(args[ARG_NOAREAS].data && args[ARG_NONODES].data)
   {
      printf("Nothing to do\n");
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   printf("CrashStats "VERSION" © "  COPYRIGHT " Johan Billing\n");

   if(!(fh=osOpen(args[ARG_FILE].data,MODE_OLDFILE)))
   {
		uint32_t err=osError();
      printf("Error opening %s\n",(char *)args[ARG_FILE].data);
		printf("Error: %s\n",osErrorMsg(err));		
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   osRead(fh,buf,4);
   buf[4]=0;

   if(strcmp(buf,STATS_IDENTIFIER)!=0)
   {
      printf("Unknown format of stats file\n");
      osClose(fh);
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   osRead(fh,&DayStatsWritten,sizeof(uint32_t));

   total=0;
   totaldupes=0;
   firsttime=0;
   areas=0;

   for(c=0;c<8;c++)
   	total8days[c]=0;

   jbNewList(&StatsList);
   jbNewList(&NodesList);

   osRead(fh,&num,sizeof(uint32_t));
   c=0;

   if(!args[ARG_NOAREAS].data)
   {
      while(c<num && osRead(fh,&dastat,sizeof(struct DiskAreaStats))==sizeof(struct DiskAreaStats))
      {
         if(!args[ARG_GROUP].data || CheckFlags(dastat.Group,args[ARG_GROUP].data))
         {
            if(!(sn=osAlloc(sizeof(struct StatsNode))))
            {
               printf("Out of memory\n");
               jbFreeList(&StatsList);
               osClose(fh);
               osEnd();
               exit(OS_EXIT_ERROR);
            }

            jbAddNode(&StatsList,(struct jbNode *)sn);

            strcpy(sn->Tagname,dastat.Tagname);
            sn->Dupes=dastat.Dupes;
            sn->Total=dastat.TotalTexts;
            sn->FirstTime=dastat.FirstTime;
            sn->LastTime=dastat.LastTime;
            memcpy(&sn->Last8Days[0],&dastat.Last8Days[0],8*sizeof(uint16_t));

            sn->Average=CalculateAverage(&dastat.Last8Days[0],dastat.TotalTexts,DayStatsWritten,sn->FirstTime / (24*60*60));
         }

         if(dastat.FirstTime!=0)
            if(firsttime==0 || firsttime > dastat.FirstTime)
               firsttime=dastat.FirstTime;

         c++;
      }
   }
   else
   {
      while(c<num && osRead(fh,&dastat,sizeof(struct DiskAreaStats))==sizeof(struct DiskAreaStats))
         c++;
   }

   osRead(fh,&num,sizeof(uint32_t));
   c=0;

   if(!args[ARG_NONODES].data)
   {
      while(c<num && osRead(fh,&dnstat,sizeof(struct DiskNodeStats))==sizeof(struct DiskNodeStats))
      {
         if(!(nsn=osAlloc(sizeof(struct NodeStatsNode))))
         {
            printf("Out of memory\n");
            jbFreeList(&NodesList);
            jbFreeList(&StatsList);
            osClose(fh);
            osEnd();
            exit(OS_EXIT_ERROR);
         }

         jbAddNode(&NodesList,(struct jbNode *)nsn);

         Copy4D(&nsn->Node,&dnstat.Node);

         nsn->GotNetmails=dnstat.GotNetmails;
         nsn->GotNetmailBytes=dnstat.GotNetmailBytes;
         nsn->SentNetmails=dnstat.SentNetmails;
         nsn->SentNetmailBytes=dnstat.SentNetmailBytes;
         nsn->GotEchomails=dnstat.GotEchomails;
         nsn->GotEchomailBytes=dnstat.GotEchomailBytes;
         nsn->SentEchomails=dnstat.SentEchomails;
         nsn->SentEchomailBytes=dnstat.SentEchomailBytes;
         nsn->Dupes=dnstat.Dupes;

         nsn->Days=DayStatsWritten-dnstat.FirstTime % (24*60*60);
         if(nsn->Days==0) nsn->Days=1;

         nsn->FirstTime=dnstat.FirstTime;

         if(dnstat.FirstTime!=0)
            if(firsttime==0 || firsttime > dnstat.FirstTime)
               firsttime=dnstat.FirstTime;

         c++;
      }
   }
   else
   {
      while(c<num && osRead(fh,&dnstat,sizeof(struct DiskNodeStats))==sizeof(struct DiskNodeStats))
         c++;
   }

   osClose(fh);

   t=(time_t)DayStatsWritten * 24*60*60;

   tp=localtime(&firsttime);
   sprintf(date,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100);
   
   tp=localtime(&t);
   sprintf(date2,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100);

   printf("\nStatistics from %s to %s\n",date,date2);
   
   if(!ctrlc && !args[ARG_NOAREAS].data)
   {
      Sort(&StatsList,'a');
      Sort(&StatsList,sortmode);
      printf("\n");

      if(args[ARG_LAST7].data)
      {
         printf("Area                             ");

         for(c=1;c<8;c++)
         {
            t=(DayStatsWritten-c)*24*60*60;
            tp=localtime(&t);
            printf("   %02d",tp->tm_mday);
         }

         printf("   Total\n============================================================================\n");

         if(!ctrlc)
         {
            for(sn=(struct StatsNode *)StatsList.First;sn && !ctrlc;sn=sn->Next)
            {
               tot=0;

               for(c=1;c<8;c++)
                  tot+=sn->Last8Days[c];

               printf("%-33.33s %4d %4d %4d %4d %4d %4d %4d : %5d\n",
                  sn->Tagname,
                  sn->Last8Days[1],
                  sn->Last8Days[2],
                  sn->Last8Days[3],
                  sn->Last8Days[4],
                  sn->Last8Days[5],
                  sn->Last8Days[6],
                  sn->Last8Days[7],
                  tot);

               for(c=1;c<8;c++)
                  total8days[c]+=sn->Last8Days[c];

               areas++;
            }

            if(!ctrlc)
            {
               tot=0;

               for(c=1;c<8;c++)
                  tot+=total8days[c];

               printf("=============================================================================\n");
               sprintf(buf,"Totally in all %u areas",areas);

               printf("%-33.33s %4d %4d %4d %4d %4d %4d %4d : %5d\n",
                  buf,
                  total8days[1],
                  total8days[2],
                  total8days[3],
                  total8days[4],
                  total8days[5],
                  total8days[6],
                  total8days[7],
                  tot);
            }
         }
      }
      else
      {
         printf("Area                           First     Last         Msgs  Msgs/day   Dupes\n");
         printf("============================================================================\n");

         if(!ctrlc)
         {
            for(sn=(struct StatsNode *)StatsList.First;sn && !ctrlc;sn=sn->Next)
            {
               if(sn->LastTime==0)
               {
                  strcpy(date2,"<Never>");
               }
               else
               {
                  tp=localtime(&sn->LastTime);
                  sprintf(date2,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100);
               }

               if(sn->FirstTime==0)
               {
                  strcpy(date,"<Never>");
               }
               else
               {
                  tp=localtime(&sn->FirstTime);
                  sprintf(date,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100);
               }

               for(c=0;c<8;c++)
                  total8days[c]+=sn->Last8Days[c];

               total+=sn->Total;
               totaldupes+=sn->Dupes;
               areas++;

               printf("%-29.30s %-9.9s %-9.9s %7d   %7d %7d\n",sn->Tagname,date,date2,sn->Total,sn->Average,sn->Dupes);
            }
         }

         if(!ctrlc)
         {
            printf("============================================================================\n");
            sprintf(buf,"Totally in all %u areas",areas);
            printf("%-42s         %7d   %7d %7d\n",
               buf,
               total,
               CalculateAverage(&total8days[0],total,DayStatsWritten,firsttime / (24*60*60)),
               totaldupes);
         }
      }
   }

   if(!ctrlc && !args[ARG_NONODES].data)
   {
      SortNodes(&NodesList);

      printf("\n");
      printf("Nodes statistics\n");
      printf("================\n");

      for(nsn=(struct NodeStatsNode *)NodesList.First;nsn && !ctrlc;nsn=nsn->Next)
      {
         if(nsn->FirstTime==0)
         {
            strcpy(date,"<Never>");
         }
         else
         {
            tp=localtime(&nsn->FirstTime);
            sprintf(date,"%0d-%s-%0d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100);
         }

         sprintf(buf,"%u:%u/%u.%u",nsn->Node.Zone,nsn->Node.Net,nsn->Node.Node,nsn->Node.Point);

			printf("%-30.40s Statistics since: %s\n\n",buf,date);
			printf("                                  Sent netmails: %u/%s\n",nsn->SentNetmails,unit(nsn->SentNetmailBytes));
			printf("                              Received netmails: %u/%s\n",nsn->GotNetmails,unit(nsn->GotNetmailBytes));
			printf("                                 Sent echomails: %u/%s\n",nsn->SentEchomails,unit(nsn->SentEchomailBytes));
			printf("                             Received echomails: %u/%s\n",nsn->GotEchomails,unit(nsn->GotEchomailBytes));
			printf("                                          Dupes: %u\n",nsn->Dupes);
         printf("\n");
      }
   }

   if(ctrlc)
   {
      printf("*** Break\n");
   }
   else
   {
      printf("\n");
   }

   jbFreeList(&StatsList);
   jbFreeList(&NodesList);

   osEnd();
   
   exit(OS_EXIT_OK);
}
Esempio n. 6
0
void ProcessARow(int scoreArray[])
{
    scoreArray[4] = CalculateMin(scoreArray[1], scoreArray[2], scoreArray[3]);
    scoreArray[5] = CalculateMax(scoreArray[1], scoreArray[2], scoreArray[3]);
    scoreArray[6] = CalculateAverage(scoreArray[1], scoreArray[2], scoreArray[3]);
}