Research weight computations

* Added game.research.weightBase constant

* Added view which computes the weights for each in-progress research

* Added view which computes total weights per empire
This commit is contained in:
Emmanuel BENOîT 2012-03-01 12:42:05 +01:00
parent c9d8a077bd
commit a14601df37
8 changed files with 150 additions and 1 deletions
legacyworlds-server-data/db-structure/tests/admin/040-functions/045-empire-research

View file

@ -0,0 +1,42 @@
/*
* Test emp.research_weights_view
*/
BEGIN;
/* Remove foreign keys from the empire research table */
ALTER TABLE emp.technologies_v2
DROP CONSTRAINT fk_emptech_empire ,
DROP CONSTRAINT fk_emptech_technology;
/* Insert a few records */
DELETE FROM emp.technologies_v2;
INSERT INTO emp.technologies_v2 (
empire_id , technology_name_id ,
emptech_state , emptech_points , emptech_priority
) VALUES
( 1 , 1 , 'RESEARCH' , 0 , 0 ) ,
( 1 , 2 , 'RESEARCH' , 0 , 1 ) ,
( 1 , 3 , 'RESEARCH' , 0 , 2 ) ,
( 1 , 4 , 'RESEARCH' , 0 , 3 ) ,
( 1 , 5 , 'RESEARCH' , 0 , 4 ) ,
( 1 , 6 , 'PENDING' , NULL , NULL ) ,
( 1 , 7 , 'KNOWN' , NULL , NULL );
/* Set the constant */
SELECT sys.uoc_constant( 'game.research.weightBase' , '(test)' , 'Test' , 10.0 );
/***** TESTS BEGIN HERE *****/
SELECT plan( 2 );
SELECT diag_test_name( 'emp.research_weights_view - Rows present' );
SELECT is( COUNT(*)::INT , 5 )
FROM emp.research_weights_view;
SELECT diag_test_name( 'emp.research_weights_view - weight = game.research.weightBase ^ priority' );
SELECT is_empty( $$
SELECT * FROM emp.research_weights_view
WHERE emptech_weight IS NULL
OR emptech_weight <> POW( 10 , technology_name_id - 1 )
$$ );
SELECT * FROM finish( );
ROLLBACK;

View file

@ -0,0 +1,35 @@
/*
* Test emp.total_mining_weights_view
*/
BEGIN;
/* Create a table which will server as an alternate source for
* emp.total_weights_view ; the table is not temporary (PostgreSQL
* won't allow replacing the view otherwise), but will be dropped
* on rollback anyway.
*/
CREATE TABLE fake_weights(
empire_id INT ,
technology_name_id INT ,
emptech_weight DOUBLE PRECISION
);
CREATE OR REPLACE VIEW emp.research_weights_view
AS SELECT * FROM fake_weights;
/* Insert fake records for two different empires */
INSERT INTO fake_weights VALUES
( 1 , 0 , 1 ) ,
( 1 , 1 , 2 ) ,
( 2 , 0 , 4 ) ,
( 2 , 1 , 5 );
/***** TESTS BEGIN HERE *****/
SELECT plan( 1 );
SELECT set_eq(
$$ SELECT * FROM emp.research_total_weights_view $$ ,
$$ VALUES ( 1 , 3.0 ) , ( 2 , 9.0 ) $$
);
SELECT * FROM finish( );
ROLLBACK;