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:
parent
c9d8a077bd
commit
a14601df37
8 changed files with 150 additions and 1 deletions
|
@ -128,7 +128,7 @@ public class ConstantsRegistrarBean
|
|||
|
||||
// Research
|
||||
String[] rcNames = {
|
||||
"basePoints" , "visibility.points" , "visibility.ratio"
|
||||
"basePoints" , "visibility.points" , "visibility.ratio" , "weightBase"
|
||||
};
|
||||
for ( int i = 0 ; i < wcNames.length ; i++ ) {
|
||||
rcNames[ i ] = "game.research." + rcNames[ i ];
|
||||
|
@ -140,6 +140,10 @@ public class ConstantsRegistrarBean
|
|||
defs.add( new ConstantDefinition( rcNames[ 1 ] , cat , cDesc , 2500.0 , 0.01 , true ) );
|
||||
cDesc = "Completion ratio above which a technology becomes visible.";
|
||||
defs.add( new ConstantDefinition( rcNames[ 2 ] , cat , cDesc , 0.10 , 0.01 , 0.99 ) );
|
||||
cDesc = "Technology weight base value. This value is taken to the Xth power (where X is a priority) "
|
||||
+ "to compute the actual weight when determining how research points are distributed between "
|
||||
+ "an empire's in-progress research.";
|
||||
defs.add( new ConstantDefinition( rcNames[ 3 ] , cat , cDesc , 10.0 , 1.0 , true ) );
|
||||
|
||||
// Vacation mode
|
||||
cDesc = "Initial vacation credits.";
|
||||
|
|
|
@ -319,6 +319,44 @@ CREATE VIEW emp.technology_visibility_view
|
|||
|
||||
|
||||
|
||||
/*
|
||||
* Research weights
|
||||
* -----------------
|
||||
*
|
||||
* This view computes weights based on priorities for each in-progress
|
||||
* research.
|
||||
*
|
||||
* Columns:
|
||||
* empire_id The empire's identifier
|
||||
* technology_name_id The technology's identifier
|
||||
* emptech_weight The weight
|
||||
*/
|
||||
DROP VIEW IF EXISTS emp.research_weights_view CASCADE;
|
||||
CREATE VIEW emp.research_weights_view
|
||||
AS SELECT empire_id , technology_name_id ,
|
||||
POW( sys.get_constant( 'game.research.weightBase' ) ,
|
||||
emptech_priority ) AS emptech_weight
|
||||
FROM emp.technologies_v2
|
||||
WHERE emptech_state = 'RESEARCH';
|
||||
|
||||
/*
|
||||
* Total research weights
|
||||
* -----------------------
|
||||
*
|
||||
* This view computes total research weights for each empire with in-progress
|
||||
* research.
|
||||
*
|
||||
* Columns:
|
||||
* empire_id The empire's identifier
|
||||
* emptech_total_weight The total research weight
|
||||
*/
|
||||
DROP VIEW IF EXISTS emp.research_total_weights_view CASCADE;
|
||||
CREATE VIEW emp.research_total_weights_view
|
||||
AS SELECT empire_id , SUM( emptech_weight ) AS emptech_total_weight
|
||||
FROM emp.research_weights_view
|
||||
GROUP BY empire_id;
|
||||
|
||||
|
||||
/*
|
||||
* Empire research and technologies
|
||||
* ---------------------------------
|
||||
|
|
|
@ -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;
|
|
@ -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;
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Test privileges on emp.research_weights_view
|
||||
*/
|
||||
BEGIN;
|
||||
\i utils/strings.sql
|
||||
|
||||
SELECT plan( 1 );
|
||||
|
||||
SELECT diag_test_name( 'emp.research_weights_view - No SELECT privilege' );
|
||||
SELECT throws_ok( $$
|
||||
SELECT * FROM emp.research_weights_view;
|
||||
$$ , 42501 );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Test privileges on emp.research_total_weights_view
|
||||
*/
|
||||
BEGIN;
|
||||
\i utils/strings.sql
|
||||
|
||||
SELECT plan( 1 );
|
||||
|
||||
SELECT diag_test_name( 'emp.research_total_weights_view - No SELECT privilege' );
|
||||
SELECT throws_ok( $$
|
||||
SELECT * FROM emp.research_total_weights_view;
|
||||
$$ , 42501 );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
Reference in a new issue