Bank update 0.8.2-0.8.5

Programmers Guild

Moderator: Andreas the Wise

Post Reply
Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Bank update 0.8.2-0.8.5

Post by Erik Mortis »

http://shireroth.org/forum/viewtopic.php?f=226&t=11410

Code: Select all

0.8.2 Fixed all Change*.php pages so that they don't mess with the session 
			unless you made changes to your accounts. Also a glich in changetype.php
			was fixed, it would mess up the users status.
0.8.3 Moved more funciton from util.php into htmllib.php and made pages aware
			of this change. Some libs are more alphabetized then previously. 
			Fixxed some XHTML issues. Created Terminal.css. Created and fixed a strange
			problem with Sessions by having one to many newlines at the end of sublib.
			Fixed subdivision error in the table related to "Elywnn". Repair.php dealt
			with it.
0.8.4 Added a note to deletesubdivision. Should I make a FAQ? There's now a blank one. 
0.8.5 stats page and gdp page, written by Andreas the Wise added. But gdp needs work. 
			tables requested for it are not implemented. Everything fixed. Config updated. 

Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Erik Mortis »

Still need to fix the userlist as requested. and need to look into fixing how logs are displayed. I still don't know why you used those table Andrea.. but there they are..

User avatar
Andreas the Wise
Posts: 5253
Joined: Sat Oct 27, 2007 10:41 pm
Location: The Island of Melangia, Atterock, Kildare
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Andreas the Wise »

When I originally was running it in access, the three things that end up in tables were queries; and the other queries ran off the results from those three queries. But I couldn't work out how to use those results in php as things for other queries to search. So I just store them in database form, which the other queries can then search.
The character Andreas the Wise is on indefinite leave.
However, this account still manages:
Cla'Udi - Count of Melangia
Manuel - CEO of VBNC. For all you'll ever need.
Vincent Waldgrave - Lord General of Gralus
Q - Director of SAMIN
Duke Mel'Kat - Air Pirate, Melangian, and Duke of the Flying Duchy of Glanurchy

And references may be made to Vur'Alm Xei'Bôn (a Nelagan Micron of undisclosed purpose).

User avatar
Ari Rahikkala
Posts: 4326
Joined: Sun Jan 21, 2001 12:56 pm
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Ari Rahikkala »

How do you calculate the GDP of a state in the bank? I could proly write a query to do that without temp tables...
No-one should be without a parasol, Sirocco.

User avatar
Andreas the Wise
Posts: 5253
Joined: Sat Oct 27, 2007 10:41 pm
Location: The Island of Melangia, Atterock, Kildare
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Andreas the Wise »

Would you like to see my code, or just the explanation behind the queries?
The character Andreas the Wise is on indefinite leave.
However, this account still manages:
Cla'Udi - Count of Melangia
Manuel - CEO of VBNC. For all you'll ever need.
Vincent Waldgrave - Lord General of Gralus
Q - Director of SAMIN
Duke Mel'Kat - Air Pirate, Melangian, and Duke of the Flying Duchy of Glanurchy

And references may be made to Vur'Alm Xei'Bôn (a Nelagan Micron of undisclosed purpose).

User avatar
Ari Rahikkala
Posts: 4326
Joined: Sun Jan 21, 2001 12:56 pm
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Ari Rahikkala »

Probably the latter, but only if it's sufficient information to actually construct the correct code :p
No-one should be without a parasol, Sirocco.

Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Erik Mortis »

the gdp.php file in the bank directory Ari. Take a look at your leisure.

User avatar
Ari Rahikkala
Posts: 4326
Joined: Sun Jan 21, 2001 12:56 pm
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Ari Rahikkala »

It's just that it'd be far easier to figure out what's going on from, you know, a description of what's going on...

Anyways, here's what I've got: You'll want the query to start with something like

Code: Select all

select sum(banklog.funds), s.country from banklog, bankaccounts as s, bankaccounts as d where banklog.source = s.username and banklog.destination = d.username
That is, s is now the name of the bank account information of the transaction's source side, and d that of the destination side. Imports and exports are easy:

Imports:

Code: Select all

select sum(banklog.funds), s.country from banklog, bankaccounts as s, bankaccounts as d where banklog.source = s.username and banklog.destination = d.username and s.country != d.country group by s.country;
Exports:

Code: Select all

select sum(banklog.funds), d.country from banklog, bankaccounts as s, bankaccounts as d where banklog.source = s.username and banklog.destination = d.username and s.country != d.country group by d.country;
You'll note that the difference is whether you select the s.country or d.country column, and in whether you group by s.country or d.country (the use of s and d here must agree). To limit this to one country, you can remove the s.country or d.country from the selection, and replace the GROUP BY clause with AND s.country='countryname' (similarly with d.country). For instance, to get Shireroth's imports,

Code: Select all

select sum(banklog.funds) from banklog, bankaccounts as s, bankaccounts as d where banklog.source = s.username and banklog.destination = d.username and s.country != d.country and s.country='Shireroth';
Consumption, investment, and government spending add a bit of stuff, though not much complexity. Basically, you just add WHERE clauses to constrain the query on s.type. They should all be obvious based on how the query for consumption (for Shireroth) looks:

Code: Select all

select sum(banklog.funds) from banklog, bankaccounts as s, bankaccounts as d where banklog.source = s.username and banklog.destination = d.username and s.country = d.country and s.country ='Shireroth' and s.type='Private';
You'll note that the queries for consumption, investment and government spending return different results with your code and mine. The values seem closer when the "s.country = d.country" restriction is removed, so I suspect the cause might be that your code doesn't restrict foreign transactions from those values (and thus quadruple-counts it in the full GDP). But I could be wrong, I'm playing by ear here.
No-one should be without a parasol, Sirocco.

User avatar
Andreas the Wise
Posts: 5253
Joined: Sat Oct 27, 2007 10:41 pm
Location: The Island of Melangia, Atterock, Kildare
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Andreas the Wise »

Originally, as I said, I did this all in access (where you can happily view what things are brought up by the query), and it seemed to give the right results. I then took the SQL from access and painstakingly changed all the input criteria. When it got up into the bank yesterday, I checked my old results against the bank results. For Natopia, I got the same. For Nelaga, the same except it excluded the "Buying of JASO" transaction. For Shireroth and Gralus, different-ish results. Now that could be because people have subsequently changed the country on their account; or accounts have been deleted (the bank can hardly know your country from the logs if the account has been deleted); but it seemed a lot more variation than I would expect to be accounted for that.

Explanation of GDP in words:
All transactions involving a given nation over a three month period.
Consumption = Transactions originating from a private citizen in the given country; to any other account.
Investment = Transactions originating from a company in the given country; to any other account.
Government = Transactions originating from a government account in the given country; to any other account.
Exports = Transactions originating from any account not in the given country; to any account in the given country.
Imports = Transactions originating from any account in the given country; to any account not in the given country.

So Imports should double count transactions already counted in C, I and G; and they are then subtracted from overall GDP.

I *think* that's how I set it up. It was a couple months ago.

On an unrelated note - Erik, thanks for sending me the tables from the database. But here's a funny thing. My system stats page gives me the same total values for each thing; but different averages. This is using, as far as I can tell, the exact same data on both the Bank version and my local version; and theoretically the same code; but my local version gives me the correct averages (one government account for the bottom four countries; one company for Gralus etc); and the bank version gives wildly incorrect averages. Did you incorporate the code exactly as I gave it to you? If so ... I wonder why its not working.
The character Andreas the Wise is on indefinite leave.
However, this account still manages:
Cla'Udi - Count of Melangia
Manuel - CEO of VBNC. For all you'll ever need.
Vincent Waldgrave - Lord General of Gralus
Q - Director of SAMIN
Duke Mel'Kat - Air Pirate, Melangian, and Duke of the Flying Duchy of Glanurchy

And references may be made to Vur'Alm Xei'Bôn (a Nelagan Micron of undisclosed purpose).

Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Erik Mortis »

I'm staying out of this. Just end me the new gdp page when/if you make one.

User avatar
Ari Rahikkala
Posts: 4326
Joined: Sun Jan 21, 2001 12:56 pm
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Ari Rahikkala »

Andreas the Wise wrote:So Imports should double count transactions already counted in C, I and G; and they are then subtracted from overall GDP.
Ah, of course, that does make sense now that I'm properly awake. I'll be doing that when I rewrite the page..

In any case the approach where you toss temporary data into the database without marking it as belonging to a specific session/page is wrong, if only in a way that'll only display itself once the bank starts getting more use: Suppose the webserver decided to schedule things just so that when one invocation of the script has finished putting its stuff in the bankgdp- tables, another one gets to run and runs all the way through before the first one gets to continue. It's unlikely, but it's this kind of thing that they put the "engineering" in "software engineering" for - just on principle, when you're writing software for multiple concurrent users, you're supposed to make it so that it doesn't randomly return bad results just because a lot of people happen to actually be using it at the same time.

I'll also have a look at bankstats.php, I guess..

BTW, I (finally) added a .htaccess containing DirectoryIndex index.php to the bank. You can now link to the bank with just http://shireroth.org/bank.
No-one should be without a parasol, Sirocco.

User avatar
Ari Rahikkala
Posts: 4326
Joined: Sun Jan 21, 2001 12:56 pm
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Ari Rahikkala »

Erik, I replaced the gdp.php and bankstats.php in the bank directory, please update your development version ASAP so you don't accidentally overwrite them.

Andreas: Did you test your code in a database containing the data for every nation? Because bankstats.php calculates the averages by dividing the nation's sum with the *total* count of a given type of account. Anyways, you can find the fixed code at http://ari-rahikkala.net/misc/bankstuff/
No-one should be without a parasol, Sirocco.

User avatar
Andreas the Wise
Posts: 5253
Joined: Sat Oct 27, 2007 10:41 pm
Location: The Island of Melangia, Atterock, Kildare
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Andreas the Wise »

Thanks Ari. I'll look at the code more tomorrow (if nothing else, it'll teach me a lot about programming neater) - though a quick check notes that it gets the same results as my localhost version for the Summary page, except for the average of Private and Government accounts overall. I got Erik to export the two bank tables for me so I can test with the full results. If you say it was calculating off the wrong averages ... Erik, did you update my bankstats page the second time I sent it to you? If not, that'd be the problem (I noticed that after the first time and updated it, Ari).
The character Andreas the Wise is on indefinite leave.
However, this account still manages:
Cla'Udi - Count of Melangia
Manuel - CEO of VBNC. For all you'll ever need.
Vincent Waldgrave - Lord General of Gralus
Q - Director of SAMIN
Duke Mel'Kat - Air Pirate, Melangian, and Duke of the Flying Duchy of Glanurchy

And references may be made to Vur'Alm Xei'Bôn (a Nelagan Micron of undisclosed purpose).

Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Erik Mortis »

You sent me the bankstats a second time?

I have the versions Ari put on the site. so now the 2nd version and his aren't the same.


I'll send Ari's copies to you for review. They are already active.

Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Erik Mortis »

oh. a note. I made the admin account part of the "Small Commonwealth" through some trickery. We need to change how we count countries. If we get a list of countries by looking at accounts, we'll get 7. If we look at the subdivision table and get the countries from there we get 6.


(I undid the trickery. Now it'll be 6 for both ways. I need to standardize that)

Just added country_count() to sublib.php. so use that to get the number of countries in the future.

Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Erik Mortis »

Code: Select all

 //Connect to Server
 $server = mysql_connect (DB_SERVER, DB_USERNAME, DB_PASSWORD); //connect to server
 if (!$server)
 print ("Could not connect to ".BANK_NAME." Server<br />");			 

 $database = mysql_select_db (DB_DATABASE, $server); //Select bank database
 if (!$database)
 print ("Could not select ".BANK_NAME." Database<br />");
Makes sure that you replace the old way of connecting with that. I had a weird variable on ALL the pages that didn't do anything. And some pages still had Shirebank hardcoded into it. bankstats was on of them. the copies of bankstats and gdp I resent you Andreas doesn't have this change.

User avatar
Andreas the Wise
Posts: 5253
Joined: Sat Oct 27, 2007 10:41 pm
Location: The Island of Melangia, Atterock, Kildare
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Andreas the Wise »

Reviewed your code, Ari. It all seems to produce the right results. One question, just for my general understanding of code:

Code: Select all

$government = isset($accountsList[$countryKey]['Government']) ? array_sum ($accountsList[$countryKey]['Government']) : 0;
Is that equivalent to

Code: Select all

if (isset($accountsList[$countryKey]['Government']))
  {$government = array_sum ($accountsList[$countryKey]['Government']);}
else
  {$government = 0;}
?

More aimed at Erik: I also worked out why GDP is different from what I calculated before. When people change their account country, it changes all their past and future contributions to GDP (as in, which country its registered in) - I knew that would happen. What I hadn't realised before was that when we delete an account, the GDP function then ignores it because it can't know which country it is (and the deletion of the Crown Account means that we know have a large chunk of Shirithian transactions which will never show up in GDP).

I seem to recall you saying somewhere you had functionality for making accounts 'inactive'. Would it be possible, instead of deleting accounts, to render them inactive, so that they stay in the accounts table (with 0 funds) and show up in GDP calculations/logs; but no longer show up on lists of users when you're trying to do a transaction?
The character Andreas the Wise is on indefinite leave.
However, this account still manages:
Cla'Udi - Count of Melangia
Manuel - CEO of VBNC. For all you'll ever need.
Vincent Waldgrave - Lord General of Gralus
Q - Director of SAMIN
Duke Mel'Kat - Air Pirate, Melangian, and Duke of the Flying Duchy of Glanurchy

And references may be made to Vur'Alm Xei'Bôn (a Nelagan Micron of undisclosed purpose).

Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Erik Mortis »

Yes. Just add a new Status to the list as Inactive. And have the lists ignore it. Just need to rewrite some functions. Maybe a few pages. I'll add it to the list.

Erik Mortis
Posts: 7238
Joined: Thu Oct 02, 2003 10:37 pm
Location: County of Monty Crisco
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Erik Mortis »

Done. Checking for brakage.

I broke something!. since I made inactive acocunts not show up in lists.. now you can't change them to active. Admins can still see inactive in user_select().

Found a new problem with how user_select_given() displays countries next to names.. it's not.

Code: Select all

function user_select($name, $server)
//create a pull down menu of users with the name="$name" (Why did I do it this way???)
//use user_select_given if possible. 
{
 $list = array();
 $list = userlist($server);
 $i = count($list);
 $j=0;

 print("<select name='".$name."' size='7'>");
 while ($j < $i)
 {
 	if (get_status($list[$j],$server) != 'Inactive' OR $_SESSION['status'] == 'Admin') //only screen for none admins. 
		print ("<option value='".$list[$j]."'>".$list[$j]." <i>(".get_country($list[$j],$server).")</i></option>");
	$j++;
 }
 print('</select>');
}
which works

Code: Select all

function user_select_given($name, $list)
//create a pull down menu of users with the name="$name" from the given list of users (To eventually replace user_select()
{
 $i = count($list);
 $j=0;

 print("<select name='".$name."' size='7'>");
 while ($j < $i)
 {
 	if (get_status($list[$j],$server) != 'Inactive' OR $_SESSION['status'] == 'Admin') //only screen for none admins. 
		print ("<option value='".$list[$j]."'>".$list[$j]." <i>(".get_country($list[$j],$server).")</i></option>");
	$j++;
 }
 print('</select>');
}
which isn't. There is no difference I can see.

BLOODY HELL!.. there it is! $server... why didn't it yell at me?

User avatar
Andreas the Wise
Posts: 5253
Joined: Sat Oct 27, 2007 10:41 pm
Location: The Island of Melangia, Atterock, Kildare
Contact:

Re: Bank update 0.8.2-0.8.5

Post by Andreas the Wise »

Excellent! I'll add back in some of the accounts I can remember deleting ...
The character Andreas the Wise is on indefinite leave.
However, this account still manages:
Cla'Udi - Count of Melangia
Manuel - CEO of VBNC. For all you'll ever need.
Vincent Waldgrave - Lord General of Gralus
Q - Director of SAMIN
Duke Mel'Kat - Air Pirate, Melangian, and Duke of the Flying Duchy of Glanurchy

And references may be made to Vur'Alm Xei'Bôn (a Nelagan Micron of undisclosed purpose).

Post Reply

Return to “Church of the Machine God”

Who is online

Users browsing this forum: No registered users and 0 guests