tweaked orders, added lookup for under/overcut via CREST

This commit is contained in:
Nicole Dresselhaus 2015-09-17 23:31:25 +02:00
parent 4016194ecb
commit 2b55cf8178
5 changed files with 168 additions and 45 deletions

View File

@ -69,6 +69,7 @@ instance Yesod App where
addStylesheet $ StaticR css_neat_css addStylesheet $ StaticR css_neat_css
addScript $ StaticR js_jquery_js addScript $ StaticR js_jquery_js
addScript $ StaticR js_bootstrap_js addScript $ StaticR js_bootstrap_js
addScript $ StaticR js_neat_js
$(widgetFile "default-layout") $(widgetFile "default-layout")
withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet") withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet")

View File

@ -9,56 +9,100 @@ import qualified Eve.Api.Char.MarketOrders as MO
getOrdersR :: Handler Html getOrdersR :: Handler Html
getOrdersR = loginOrDo (\(uid,user) -> do getOrdersR = loginOrDo (\(uid,user) -> do
-- using raw because model does not know about CCP-Data-Dump -- using raw because model does not know about CCP-Data-Dump
let sql = "select ??, t.\"typeName\" from \"order\" join \"invTypes\" t on (\"order\".type_id = t.\"typeID\") where \"user\"=? order by \"order\".is_sell asc, t.\"typeName\" asc" let sql = "select ??, t.\"typeName\", s.\"stationName\", s.\"regionID\" from \"order\" join \"invTypes\" t on (\"order\".type_id = t.\"typeID\") join \"staStations\" s on (\"order\".station_id = s.\"stationID\") where \"user\"=? order by \"order\".is_sell asc, t.\"typeName\" asc"
(orders :: [(Entity Order, Single Text)]) <- runDB $ rawSql sql [toPersistValue uid] (orders :: [(Entity Order, Single Text, Single Text, Single Text)]) <- runDB $ rawSql sql [toPersistValue uid]
let sellorders = filter (\(Entity _ o, _) -> orderIsSell o && orderOrderState o == (fromIntegral . fromEnum) MO.Open) orders let f = \(a,_,_,_) -> a
let buyorders = filter (\(Entity _ o, _) -> not (orderIsSell o) && orderOrderState o == (fromIntegral . fromEnum) MO.Open) orders let sellorders = filter (\(Entity _ o, _, _, _) -> orderIsSell o && orderOrderState o == (fromIntegral . fromEnum) MO.Open) orders
let sellsum = foldl' sumOrders 0 (f <$> sellorders)
let sellescrow = foldl' sumEscrow 0 (f <$> sellorders)
let buyorders = filter (\(Entity _ o, _, _, _) -> not (orderIsSell o) && orderOrderState o == (fromIntegral . fromEnum) MO.Open) orders
let buysum = foldl' sumOrders 0 (f <$> buyorders)
let buyescrow = foldl' sumEscrow 0 (f <$> buyorders)
loginLayout user [whamlet| loginLayout user [whamlet|
<div class="btn-group btn-group-justified">
<div class="btn-group">
<button type="button" class="btn btn-primary" onclick="checkOrders();">Check Over/Undercut
<div class="btn-group">
<button type="button" class="btn btn-primary">Feature x
<div class="btn-group">
<button type="button" class="btn btn-primary">Feature y
<div .panel .panel-default> <div .panel .panel-default>
<div .panel-heading>Current Sell Orders: <div .panel-heading>Current Sell Orders:
<table .table .table-condensed .small> <table .table .table-condensed .small .sellOrders>
<tr> <tr>
<th .text-center>Last changed <th .text-center>Last changed
<th .text-center>Item <th .text-center>Item
<th .text-center>Price <th .text-center>Price
<th .text-center>Quantity (min) <th .text-center>Quantity (min)
<th .text-center>Value
<th .text-center>Range <th .text-center>Range
<th .text-center>Duration <th .text-center>Duration
<th .text-center>Escrow <th .text-center>Escrow
<th .text-center>Station <th .text-center>Station
$forall (Entity _ o, Single name) <- sellorders $forall (Entity _ o, Single name, Single stationname, Single regionid) <- sellorders
<tr> <tr .order data="#{orderTypeId o};#{regionid};#{orderPriceCents o}">
<td>#{showDateTime $ orderIssued $ o} <td>#{showDateTime $ orderIssued $ o}
<td>#{name} <td>#{name}
<td .numeric>#{prettyISK $ orderPriceCents o} <td .numeric .price>#{prettyISK $ orderPriceCents o}
<td .numeric>#{orderVolRemaining o}/#{orderVolEntered o} (#{orderMinVolume o}) <td .numeric>#{orderVolRemaining o}/#{orderVolEntered o} (#{orderMinVolume o})
<td .numeric>Range <td .numeric>#{prettyISK $ orderVolRemaining o * orderPriceCents o}
<td .numeric>#{prettyRange $ orderRange o}
<td .numeric>#{orderDuration o} <td .numeric>#{orderDuration o}
<td .numeric>#{prettyISK $ orderEscrowCents o} <td .numeric>#{prettyISK $ orderEscrowCents o}
<td>StationName <td>#{stationname}
<tr .total>
<td>Total
<td>
<td>
<td>
<td .numeric>#{prettyISK $ sellsum}
<td>
<td>
<td .numeric>#{prettyISK $ sellescrow}
<td>
<div .panel .panel-default> <div .panel .panel-default>
<div .panel-heading>Current Buy Orders: <div .panel-heading>Current Buy Orders:
<table .table .table-condensed .small> <table .table .table-condensed .small .buyOrders>
<tr> <tr>
<th .text-center>Last changed <th .text-center>Last changed
<th .text-center>Item <th .text-center>Item
<th .text-center>Price <th .text-center>Price
<th .text-center>Quantity (min) <th .text-center>Quantity (min)
<th .text-center>Value
<th .text-center>Range <th .text-center>Range
<th .text-center>Duration <th .text-center>Duration
<th .text-center>Escrow <th .text-center>Escrow
<th .text-center>Station <th .text-center>Station
$forall (Entity _ o, Single name) <- buyorders $forall (Entity _ o, Single name, Single stationname, Single regionid) <- buyorders
<tr> <tr .order data="#{orderTypeId o};#{regionid};#{orderPriceCents o}">
<td>#{showDateTime $ orderIssued $ o} <td>#{showDateTime $ orderIssued $ o}
<td>#{name} <td>#{name}
<td .numeric>#{prettyISK $ orderPriceCents o} <td .numeric .price>#{prettyISK $ orderPriceCents o}
<td .numeric>#{orderVolRemaining o}/#{orderVolEntered o} (#{orderMinVolume o}) <td .numeric>#{orderVolRemaining o}/#{orderVolEntered o} (#{orderMinVolume o})
<td .numeric>Range <td .numeric>#{prettyISK $ orderPriceCents o * orderVolRemaining o}
<td .numeric>#{prettyRange $ orderRange o}
<td .numeric>#{orderDuration o} <td .numeric>#{orderDuration o}
<td .numeric>#{prettyISK $ orderEscrowCents o} <td .numeric>#{prettyISK $ orderEscrowCents o}
<td>StationName <td>#{stationname}
<tr .total>
<td>Total
<td>
<td>
<td>
<td .numeric>#{prettyISK $ buysum}
<td>
<td>
<td .numeric>#{prettyISK $ buyescrow}
<td>
|] |]
) )
sumOrders :: Int64 -> Entity Order -> Int64
sumOrders s (Entity _ o) = s + orderPriceCents o * orderVolRemaining o
sumEscrow :: Int64 -> Entity Order -> Int64
sumEscrow s (Entity _ o) = s + orderEscrowCents o
prettyRange :: Int32 -> String
prettyRange = show . (toEnum :: Int -> MO.Range) . fromIntegral

View File

@ -61,6 +61,7 @@ loginLayout user widget = do
addStylesheet $ StaticR css_neat_css addStylesheet $ StaticR css_neat_css
addScript $ StaticR js_jquery_js addScript $ StaticR js_jquery_js
addScript $ StaticR js_bootstrap_js addScript $ StaticR js_bootstrap_js
addScript $ StaticR js_neat_js
$(widgetFile "default-layout") $(widgetFile "default-layout")
withUrlRenderer $(hamletFile "templates/login-layout-wrapper.hamlet") withUrlRenderer $(hamletFile "templates/login-layout-wrapper.hamlet")

View File

@ -14,6 +14,14 @@
background-color: #ffcccc; background-color: #ffcccc;
} }
.outbid {
background-color: #ffcccc;
}
.not_outbid {
background-color: #33cc33;
}
.profit { .profit {
background-color: #88ff88; background-color: #88ff88;
} }

69
static/js/neat.js Normal file
View File

@ -0,0 +1,69 @@
/*
neat utility functions
*/
Number.prototype.formatMoney = function(c, d, t) {
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "." : t,
t = t == undefined ? "," : d,
s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
function checkOrders() {
$('table.sellOrders tr.order').each(function(ix,el) {
var d = $(el).attr('data').split(';');
$.getJSON("https://public-crest.eveonline.com/market/"+d[1]+"/orders/sell/?type=https://public-crest.eveonline.com/types/"+d[0]+"/",function(ret, status, xhr) {
var outbid = false;
var outbidprice = parseFloat(d[2])/100;
$(ret.items).each(function(index,order) {
if (order.price < parseFloat(d[2])/100) {
outbid = true;
if (order.price < outbidprice) {
outbidprice = order.price;
}
}
});
if (outbid) {
$(el).addClass('outbid');
var priceel = $(el).find('.price');
priceel.html(function(index, old) {
return old + "<br />" + outbidprice.formatMoney(2);
});
} else {
$(el).addClass('not_outbid');
}
});
});
$('table.buyOrders tr.order').each(function(ix,el) {
var d = $(el).attr('data').split(';');
$.getJSON("https://public-crest.eveonline.com/market/"+d[1]+"/orders/buy/?type=https://public-crest.eveonline.com/types/"+d[0]+"/",function(ret, status, xhr) {
var outbid = false;
var outbidprice = parseFloat(d[2])/100;
$(ret.items).each(function(index,order) {
if (order.price > parseFloat(d[2])/100) {
outbid = true;
if (order.price > outbidprice) {
outbidprice = order.price;
}
}
});
if (outbid) {
$(el).addClass('outbid');
var priceel = $(el).find('.price');
priceel.html(function(index, old) {
return old + "<br />" + outbidprice.formatMoney(2);
});
} else {
$(el).addClass('not_outbid');
}
});
});
}