Skip to content

Commit

Permalink
Determine if a stat is ticking and show it. BlueHerons#111
Browse files Browse the repository at this point in the history
  • Loading branch information
johnluetke committed Aug 27, 2015
1 parent 9bc364d commit b799e11
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
4 changes: 4 additions & 0 deletions database/functions/GetRateForAgentAndStatBetweenDates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ SELECT count(*),
SELECT (((@n * @sumXY) - (@sumX * @sumY)) / ((@n * @sumX2) - (@sumX * @sumX))) INTO @slope;
SELECT ((@sumY - (@slope * @sumX)) / @n) INTO @intercept;

IF stat_key = 'oldest_portal' OR stat_key = 'hacking_streak' THEN
SELECT 1 INTO @slope;
END IF;

RETURN @slope;

END $$
Expand Down
16 changes: 16 additions & 0 deletions database/functions/IsStatTicking.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
DELIMITER $$

DROP FUNCTION IF EXISTS `IsStatTicking` $$

CREATE FUNCTION `IsStatTicking`(`agent_name` VARCHAR(15), `stat_name` VARCHAR(20)) RETURNS tinyint(1)
READS SQL DATA
BEGIN

RETURN
(SELECT (most_recent.date - previous.date) = (most_recent.value - previous.value)
FROM (SELECT date, value FROM Data WHERE agent = agent_name AND stat = stat_name ORDER BY date DESC LIMIT 1) most_recent,
(SELECT date, value FROM Data WHERE agent = agent_name AND stat = stat_name ORDER BY date DESC LIMIT 1,1) previous);

END $$

DELIMITER ;
32 changes: 16 additions & 16 deletions database/procedures/GetBadgePrediction.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ SELECT amount_required INTO @y FROM Badges WHERE stat = stat_key AND level = @ne

SELECT @remaining / @slope INTO @days;

IF stat_key = 'oldest_portal' THEN
SELECT @remaining INTO @days;
IF stat_key = 'oldest_portal' OR stat_key = 'hacking_streak' THEN
SELECT @remaining INTO @days;
END IF;

IF @days < 0 THEN
SELECT 0 INTO @days;
SELECT 0 INTO @days;
END IF;

CREATE TEMPORARY TABLE BadgePrediction
SELECT stat_key `stat`,
@stat `name`,
@unit `unit`,
@badge `badge`,
@current `current`,
@next `next`,
IF((@max / @y) > .99, .99, ROUND(@max / @y, 2)) `progress`,
@max `obtained`,
@remaining `remaining`,
ROUND(@days, 1) `days`,
ROUND(@slope, 0) `rate`,
ROUND(@intercept) `intercept`,
ROUND(@slope, 2) `slope`;
SELECT stat_key `stat`,
@stat `name`,
@unit `unit`,
@badge `badge`,
@current `current`,
@next `next`,
IF((@max / @y) > .99, .99, ROUND(@max / @y, 2)) `progress`,
@max `obtained`,
@remaining `remaining`,
ROUND(@days, 1) `days`,
ROUND(@slope, 0) `rate`,
ROUND(@intercept) `intercept`,
ROUND(@slope, 0) `slope`;

END $$

Expand Down
2 changes: 1 addition & 1 deletion database/procedures/GetUpcomingBadges.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ INSERT INTO UpcomingBadges (stat, badge, next, progress, days_remaining)
d.date = @latest_submission AND
b.amount_required > d.value AND
d.value > 0 AND
s.prediction = 1
(s.prediction = 1 OR (((b.stat = 'oldest_portal') OR (b.stat = 'hacking_streak')) AND IsStatTicking(agent_name, b.stat)))
GROUP BY b.stat
ORDER BY remaining ASC;

Expand Down

0 comments on commit b799e11

Please sign in to comment.