getRate() speedup from Leo

This commit is contained in:
Andreas Kool 1999-07-26 16:28:51 +00:00
parent 153950b1ce
commit 08837858df
5 changed files with 113 additions and 69 deletions

View File

@ -17,7 +17,7 @@ U:%.3f
P:01,1 Telekom Austria
C:maintained by: Michael Reinelt <reinelt@eunet.at>
C:Tarif: Minimumtarif (ATS 1.116 pro Einheit)
# Tarif: Minimumtarif (ATS 1.116 pro Einheit)
D:pta # Verzonung
Z:0 FreePhone
@ -243,7 +243,7 @@ T:E,H/*=1.116/15 Sparzeit
A:+43717
P:01,2 Telekom Austria
C:Tarif: Standartarif (ATS 1.056 pro Einheit)
# Tarif: Standartarif (ATS 1.056 pro Einheit)
D:pta # Verzonung
Z:0 FreePhone
@ -469,7 +469,7 @@ T:E,H/*=1.056/15 Sparzeit
A:+43717
P:01,3 Telekom Austria
C:Tarif: Geschäftstarif 1 (ATS 0.996 pro Einheit)
# Tarif: Geschäftstarif 1 (ATS 0.996 pro Einheit)
D:pta # Verzonung
Z:0 FreePhone
@ -695,7 +695,7 @@ T:E,H/*=0.996/15 Sparzeit
A:+43717
P:01,4 Telekom Austria
C:Tarif: Geschäftstarif 2 (ATS 0.936 pro Einheit)
# Tarif: Geschäftstarif 2 (ATS 0.936 pro Einheit)
D:pta # Verzonung
Z:0 FreePhone
@ -921,7 +921,7 @@ T:E,H/*=0.936/15 Sparzeit
A:+43717
P:02 UTA
C:Fixme: angrenzende Bezirke werden falsch verzont
# Fixme: angrenzende Bezirke werden falsch verzont
D:uta # Verzonung
Z:1 Bundeslandzone
T:1-5/8-18=1.00(60)/1 Geschäftszeit
@ -1038,7 +1038,7 @@ A:Pakistan, Palau, Salomonen, Senegal, Seychellen, Somalia, Tokelau, Tschad
A:Tuvalu, Vietnam, Wake-Inseln, Wallis- und Futuna-Inseln, Zaire
P:03 Multikom
C:Fixme: Verzonung nicht verifiziert
# Fixme: Verzonung nicht verifiziert
D:pta # Verzonung
Z:1 Regionalzone
T:*/*=1.00(60)/60/1 rund um die Uhr
@ -1153,9 +1153,9 @@ T:*/*=19.00(60)/60/1 rund um die Uhr
A:+ alle übrigen Länder
P:07,1 European Telecom
C:Fixme: Verzonung nicht verifiziert
# Fixme: Verzonung nicht verifiziert
D:1007 # Verzonung
C:Tarif: 1 Jahr feste Bindung
# Tarif: 1 Jahr feste Bindung
Z:1 Fernzone 1
T:1-5/08-12=2.376(60)/1 Tageszeit 1
T:1-4/13-16=2.376(60)/1 Tageszeit 1
@ -1285,9 +1285,9 @@ T:1-5/18-8=1.980(60)/1 Sparzeit
T:E,H/*=1.980(60)/1 Sparzeit
P:07,2 European Telecom
C:Fixme: Verzonung nicht verifiziert
# Fixme: Verzonung nicht verifiziert
D:1007 # Verzonung
C:Tarif: 14-tägig kündbar
# Tarif: 14-tägig kündbar
Z:1 Fernzone 1
T:1-5/08-12=2.532(60)/1 Tageszeit 1
T:1-4/13-16=2.532(60)/1 Tageszeit 1
@ -1559,7 +1559,7 @@ T:*/*=24.90(60)/60/1 rund um die Uhr
A:+ alle übrigen Länder
P:24 Telepassport
C:Fixme: 'International D': Zentral- und Südamerika nicht implementiert
# Fixme: 'International D': Zentral- und Südamerika nicht implementiert
D:1024 # Verzonung
Z:1 Regionalzone
T:1-5/8-18=0.98(60)/1 Tag
@ -1617,8 +1617,8 @@ T:*/*=19.98(60)/1 rund um die Uhr
A:+ alle übrigen Länder
P:29,1 CyberTron
C:Tarif: easy.Talk privat (ATS 1.116 pro Einheit)
C:Fixme: Internationale Zonen nicht implementiert!
# Tarif: easy.Talk privat (ATS 1.116 pro Einheit)
# Fixme: Internationale Zonen nicht implementiert!
Z:1 Regionalzone
T:1-5/8-12=0.99(60)/1.1273 Tageszeit 1
T:1-4/13-16=0.99(60)/1.1273 Tageszeit 1
@ -1665,8 +1665,8 @@ Z:9 International
A:+ alle übrigen Länder
P:29,2 CyberTron
C:Tarif: easy.Talk business (ATS 1.029 pro Einheit)
C:Fixme: Internationale Zonen nicht implementiert!
# Tarif: easy.Talk business (ATS 1.029 pro Einheit)
# Fixme: Internationale Zonen nicht implementiert!
Z:1 Regionalzone
T:*/*=0.96(60)/1.0719 rund um die Uhr
Z:2 Fernzone 1
@ -1700,7 +1700,7 @@ A:+ alle
P:44 Citykom
D:1012 # Verzonung
C:Fixme: internationale Zonen nicht implementiert
# Fixme: internationale Zonen nicht implementiert
Z:1 Regional
T:*/*=0.72(60)/1 rund um die Uhr
Z:2 Österreich
@ -1716,7 +1716,7 @@ A:+ alle
P:66 MIT 1066
D:1066 # Verzonung
C:Fixme Verzonung -50/+50 nicht verifiziert
# Fixme Verzonung -50/+50 nicht verifiziert
Z:1 Regionalzone
T:1-5/8-18=0.96(60)/18.75/1 Tag
T:1-5/18-8=0.80(60)/22.50/1 Nacht

View File

@ -19,6 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.13 1999/07/25 15:57:46 akool
* isdnlog-3.43
* added "telnum" module
*
* Revision 1.12 1999/07/24 08:45:17 akool
* isdnlog-3.42
* rate-de.dat 1.02-Germany [18-Jul-1999 10:44:21]
@ -95,7 +99,7 @@ static int exclude=0;
static int is_daemon=0;
static TELNUM srcnum, destnum;
typedef struct {
int prefix;
double rate;
@ -156,8 +160,8 @@ static void init()
if (verbose && *version)
print_msg(PRT_V, "%s\n", version);
initTelNum();
initTelNum();
} /* init */
/* calc a day/time W | E | H */
@ -198,10 +202,10 @@ static void post_init()
if (fromarea) {
Strncpy(srcnum.area, fromarea, TN_MAX_AREA_LEN);
free(fromarea);
fromarea=0;
fromarea=0;
}
initNum(&srcnum);
if (wanted_day)
get_day(wanted_day);
} /* post_init */
@ -231,7 +235,7 @@ static int opts(int argc, char *argv[])
year = atoi(p + 1);
if (year < 50)
year += 2000;
else if (year < 100)
else if (year < 100)
year += 1900;
}
}
@ -248,7 +252,7 @@ static int opts(int argc, char *argv[])
}
break;
case 'h': hour = atoi(optarg);
case 'h': hour = atoi(optarg);
if ((p = strchr(optarg + 1, ':'))) {
min = atoi(p + 1);
if ((p = strchr(p + 1, ':')))
@ -269,7 +273,7 @@ static int opts(int argc, char *argv[])
providers[n_providers] = atoi(p);
p = strtok(0, ",");
n_providers++;
}
}
break;
case 'v' : verbose++;
break;
@ -473,12 +477,12 @@ static int compute(char *num)
Rate.src[2] = "";
oldprov = destnum.nprovider;
if (destnum.nprovider == UNKNOWN)
if (destnum.nprovider == UNKNOWN)
destnum.nprovider=i;
if (normalizeNumber(num, &destnum, TN_ALL) == UNKNOWN) {
destnum.nprovider=oldprov;
continue;
}
}
destnum.nprovider=oldprov;
Rate.dst[0] = destnum.country?destnum.country->Code[0] : "";
@ -549,7 +553,7 @@ static int compute(char *num)
else if (explain == 1) {
sprintf(s, " (%s)", Rate.Zone);
sort[n].explain = strdup(s);
}
}
else
sort[n].explain = strdup("");
@ -565,7 +569,7 @@ static int compute(char *num)
static void print_header(void) {
print_msg(PRT_NORMAL, "Eine %d Sekunden lange Verbindung von %s nach %s kostet am %s\n",
duration, formatNumber("%f",&srcnum), formatNumber("%f",&destnum),
duration, formatNumber("%f",&srcnum), formatNumber("%f",&destnum),
ctime(&start));
}
static void printList(char *target, int n) {
@ -595,7 +599,7 @@ static void result(char *target, int n)
n = best;
if (explain < 10)
for (i = 0; i < n; i++)
print_msg(PRT_NORMAL, "%s %s %8.3f%s\n",
print_msg(PRT_NORMAL, "%s %s %8.4f%s\n",
Provider(sort[i].prefix), currency, sort[i].rate, sort[i].explain);
} /* result */
@ -849,7 +853,7 @@ static void doit(int i, int argc, char *argv[]) {
else
result(argv[i], n);
purge(n);
}
}
i++;
} /* while */
clean_up();

View File

@ -203,7 +203,7 @@ void rate_1001_old(void) {
if (t==0)
rprintf ("Michael Reinelt <reinelt@eunet.at>", "C:maintained by:");
sprintf (s, "%s (ATS %.3f pro Einheit)", Name[t], Tarif[t]);
rprintf (s, "C:Tarif:");
rprintf (s, "# Tarif:");
rprintf ("# Verzonung", "D:pta");
for (z=0; z<COUNT(Zone); z++) {
printf ("\n");
@ -320,7 +320,7 @@ void rate_1001(void) {
if (t==0)
rprintf ("Michael Reinelt <reinelt@eunet.at>", "C:maintained by:");
sprintf (s, "%s (ATS %.3f pro Einheit)", Name[t], Tarif[t]);
rprintf (s, "C:Tarif:");
rprintf (s, "# Tarif:");
rprintf ("# Verzonung", "D:pta");
for (z=0; z<COUNT(Zone); z++) {
printf ("\n");
@ -384,7 +384,7 @@ void rate_1002(void) {
printf ("\n");
rprintf ("UTA", "P:02");
rprintf ("angrenzende Bezirke werden falsch verzont", "C:Fixme:");
rprintf ("angrenzende Bezirke werden falsch verzont", "# Fixme:");
rprintf ("# Verzonung", "D:uta");
for (z=0; z<COUNT(Zone); z++) {
rprintf (Zone[z][0], "Z:%d", z+1);
@ -437,7 +437,7 @@ void rate_1003(void) {
printf ("\n");
rprintf ("Multikom", "P:03");
rprintf ("Verzonung nicht verifiziert", "C:Fixme:");
rprintf ("Verzonung nicht verifiziert", "# Fixme:");
rprintf ("# Verzonung", "D:pta");
for (z=0; z<COUNT(Zone); z++) {
rprintf (Zone[z][0], "Z:%d", z+1);
@ -545,9 +545,9 @@ void rate_1007(void) {
for (t=0; t<2; t++) {
printf ("\n");
rprintf ("European Telecom", "P:07,%d", t+1);
rprintf ("Verzonung nicht verifiziert", "C:Fixme:");
rprintf ("Verzonung nicht verifiziert", "# Fixme:");
rprintf ("# Verzonung", "D:1007");
rprintf (Name[t], "C:Tarif:");
rprintf (Name[t], "# Tarif:");
for (z=0; z<COUNT(Zone); z++) {
rprintf (Zone[z][0], "Z:%d", z+1);
if (Tarif[t][z][0]==Tarif[t][z][1]) {
@ -711,7 +711,7 @@ void rate_1024(void) {
printf ("\n");
rprintf ("Telepassport", "P:24");
rprintf ("'International D': Zentral- und Südamerika nicht implementiert", "C:Fixme:");
rprintf ("'International D': Zentral- und Südamerika nicht implementiert", "# Fixme:");
rprintf ("# Verzonung", "D:1024");
for (z=0; z<COUNT(Zone); z++) {
rprintf (Zone[z][0], "Z:%d", z+1);
@ -770,8 +770,8 @@ void rate_1029(void) {
printf ("\n");
rprintf ("CyberTron", "P:29,%d", t+1);
sprintf (s, "%s (ATS %.3f pro Einheit)", Name[t], Einheit[t]);
rprintf (s, "C:Tarif:");
rprintf ("Internationale Zonen nicht implementiert!", "C:Fixme:");
rprintf (s, "# Tarif:");
rprintf ("Internationale Zonen nicht implementiert!", "# Fixme:");
for (z=0; z<COUNT(Zone); z++) {
rprintf (Zone[z][0], "Z:%d", z+1);
@ -818,7 +818,7 @@ void rate_1044(void) {
printf ("\n");
rprintf ("Citykom", "P:44");
rprintf ("# Verzonung", "D:1012");
rprintf ("internationale Zonen nicht implementiert", "C:Fixme:");
rprintf ("internationale Zonen nicht implementiert", "# Fixme:");
for (z=0; z<COUNT(Zone); z++) {
rprintf (Zone[z][0], "Z:%d", z+1);
if (Tarif [z][0]!=0.0) { /* Tarif bekannt? */
@ -921,7 +921,7 @@ void rate_1066(void) {
printf ("\n");
rprintf ("MIT 1066", "P:66");
rprintf ("# Verzonung", "D:1066");
rprintf ("Verzonung -50/+50 nicht verifiziert", "C:Fixme");
rprintf ("Verzonung -50/+50 nicht verifiziert", "# Fixme");
for (z=0; z<COUNT(Zone); z++) {
rprintf (Zone[z][0], "Z:%d", z+1);
if (Tarif[z][0]==Tarif[z][1]) {

View File

@ -19,6 +19,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.36 1999/07/18 08:41:19 akool
* fix from Michael
*
* Revision 1.35 1999/07/15 16:42:10 akool
* small enhancement's and fixes
*
@ -1168,8 +1171,8 @@ int getRate(RATE *Rate, char **msg)
ZONE *Zone;
HOUR *Hour;
UNIT *Unit;
int prefix, freeze, hour, cur, max, i, j;
double now, run, end, jmp;
int prefix, freeze, cur, max, i, j;
double now, end, jmp, leap;
char *day;
time_t time;
struct tm tm;
@ -1248,17 +1251,17 @@ int getRate(RATE *Rate, char **msg)
Zone=&Provider[prefix].Zone[Rate->_zone];
Hour=NULL;
Unit=NULL;
hour=UNKNOWN; /* Stundenwechsel erzwingen */
freeze=0;
now=Rate->start;
end=Rate->now;
Rate->Time=end-now;
run=0.0;
while (end>=now) {
time=now;
tm=*localtime(&time);
if (hour==UNKNOWN || (!freeze && hour!=tm.tm_hour)) { /* Neuberechnung bei Stundenwechsel */
hour=tm.tm_hour;
now=0.0;
end=Rate->now-Rate->start;
Rate->Time=end;
leap=UNKNOWN; /* Stundenwechsel erzwingen */
while (now<end) {
if (!freeze && now>=leap) { /* Neuberechnung bei Stundenwechsel */
time=Rate->start+now;
leap=3600*(int)(time/3600+1)-Rate->start;
tm=*localtime(&time);
hourBits=1<<tm.tm_hour;
Hour=NULL;
cur=max=0;
@ -1278,31 +1281,34 @@ int getRate(RATE *Rate, char **msg)
freeze=Hour->Freeze;
Rate->Hour=Hour->Name;
Unit=Hour->Unit;
jmp=run;
jmp=now;
while (Unit->Delay!=UNKNOWN && Unit->Delay<=jmp) {
jmp-=Unit->Delay;
Unit++;
}
if (now==0.0 && Unit->Duration==0.0)
Rate->Basic=Unit->Price;
else
Rate->Price=Unit->Price;
Rate->Duration=Unit->Duration;
}
now+=Unit->Duration;
run+=Unit->Duration;
now+=Unit->Duration;
Rate->Charge+=Unit->Price;
Rate->Duration=Unit->Duration;
if (run==0.0 && Unit->Duration==0.0)
Rate->Basic=Unit->Price;
else
Rate->Price=Unit->Price;
if (Unit->Duration>0.0)
Rate->Units++;
if (Unit->Delay!=UNKNOWN && Unit->Delay<=run)
if (Unit->Delay!=UNKNOWN && Unit->Delay<=now) {
Unit++;
else if (Unit->Duration==0.0)
Rate->Price=Unit->Price;
Rate->Duration=Unit->Duration;
} else if (Unit->Duration==0.0)
break;
}
if (run>0.0)
Rate->Rest=run-Rate->Time;
if (now>0.0)
Rate->Rest=now-Rate->Time;
return 0;
}
@ -1423,7 +1429,7 @@ void main (int argc, char *argv[])
printf ("%s\n", msg);
clearRate(&Rate);
Rate.prefix = 1;
Rate.prefix = 2;
if (argc==3) {
getNumber (argv[1], Rate.src);
@ -1436,6 +1442,32 @@ void main (int argc, char *argv[])
getNumber (strdup("+43-1-4711"), Rate.dst);
}
time(&Rate.start);
Rate.now=Rate.start;
for (i=0; i<5000; i++) {
if (getRate(&Rate, &msg)==UNKNOWN) {
printf ("Ooops: %s\n", msg);
exit (1);
}
Rate.now++;
}
printf ("domestic=%d _area=%d _zone=%d zone=%d Country=%s Zone=%s Service=%s Flags=%s\n"
"current=%s\n\n",
Rate.domestic, Rate._area, Rate._zone, Rate.zone, Rate.Country, Rate.Zone,
Rate.Service, Rate.Flags, explainRate(&Rate));
now=*localtime(&Rate.now);
printf ("---Date--- --Time-- --Charge-- ( Basic Price) Unit Dur Time Rest\n");
printf ("%02d.%02d.%04d %02d:%02d:%02d %10s (%6.3f %6.3f) %4d %4.1f %4ld %4ld %s\n",
now.tm_mday, now.tm_mon+1, now.tm_year+1900,
now.tm_hour, now.tm_min, now.tm_sec,
printRate (Rate.Charge), Rate.Basic, Rate.Price, Rate.Units, Rate.Duration, Rate.Time, Rate.Rest,
explainRate(&Rate));
exit (0);
#if 1
time(&Rate.start);
Rate.now=Rate.start+153;

View File

@ -19,6 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.14 1999/07/25 15:58:13 akool
* isdnlog-3.43
* added "telnum" module
*
* Revision 1.13 1999/07/10 21:38:54 akool
* isdnlog-3.41
* rate-de.dat V:1.02-Germany [10-Jul-1999 23:32:27]
@ -80,7 +84,10 @@
*
* Changes:
*
* 1.21 1997.07.22 lt fixed bug, were T was overwritten, when an 'A'
* 1.22 1999.07.26 lt bug fix, getZone returned junk, when diff. providers
* used the same zone file
*
* 1.21 1999.07.22 lt fixed bug, were T was overwritten, when an 'A'
* followed versio, occured w. DTAG
*
* 1.20 1999.07.08 lt added support for NL
@ -136,7 +143,7 @@ struct sth {
static struct sth *sthp;
static int count;
static char version[] = "1.21";
static char version[] = "1.22";
static bool area_read = false;
#define LINK 127
@ -350,6 +357,7 @@ static int _initZone(int provider, char *path, char **msg, bool area_only)
sthp[ocount].pack_key = sthp[i].pack_key;
sthp[ocount].pack_table = sthp[i].pack_table;
sthp[ocount].table = sthp[i].table;
sthp[ocount].cc = sthp[i].cc;
sthp[i].used++;
sthp[ocount].real = i;
found = true;