add page for items with bugged listing metric
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is failing Details

This commit is contained in:
Mash Potato 2023-03-24 21:20:13 -06:00
parent 3a665442bc
commit b7e9c3a60d
3 changed files with 65 additions and 12 deletions

View File

@ -458,9 +458,9 @@ func itemsListHandler(w http.ResponseWriter, _ *http.Request) {
func staleItemsListHandler(w http.ResponseWriter, _ *http.Request) {
// Remap our data into a smaller object, we don't need full data for the front end
type ResponseDataItem struct {
ID int `json:"id"`
Name string `json:"name"`
LastUpdated string `json:"lastupdated"`
ID int `json:"id"`
Name string `json:"name"`
Data string `json:"data"`
}
var responseDataItemSlice []MarketItem
for _, item := range items {
@ -486,9 +486,56 @@ func staleItemsListHandler(w http.ResponseWriter, _ *http.Request) {
for _, item := range responseDataItemSlice {
responseDataItem := ResponseDataItem{
ID: item.ID,
Name: item.Name,
LastUpdated: time.Unix(item.MarketBoardListing.LastUploadTime/1000, 0).Format("2006-01-02"),
ID: item.ID,
Name: item.Name,
Data: time.Unix(item.MarketBoardListing.LastUploadTime/1000, 0).Format("2006-01-02"),
}
responseData = append(responseData, responseDataItem)
}
jsonBytes, err := json.Marshal(responseData)
if err != nil {
log.Printf("itemsListHandler failed to marshal json to bytes: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Write(jsonBytes)
}
// http - GET /bugged-metric-items-list
// Returns a list of
func buggedMetricItemsListHandler(w http.ResponseWriter, _ *http.Request) {
// Remap our data into a smaller object, we don't need full data for the front end
type ResponseDataItem struct {
ID int `json:"id"`
Name string `json:"name"`
Data string `json:"data"`
}
var responseDataItemSlice []MarketItem
for _, item := range items {
if item.ListingMetric != 0 {
continue
}
responseDataItemSlice = append(responseDataItemSlice, *(items[item.ID]))
}
// Sort the item slice by time last updated
sort.Slice(responseDataItemSlice, func(i, j int) bool {
return responseDataItemSlice[i].MarketBoardListing.LastUploadTime < responseDataItemSlice[j].MarketBoardListing.LastUploadTime
})
if len(responseDataItemSlice) > 600 {
responseDataItemSlice = responseDataItemSlice[:600] // truncate to top 600
}
responseData := make([]ResponseDataItem, 0)
for _, item := range responseDataItemSlice {
responseDataItem := ResponseDataItem{
ID: item.ID,
Name: item.Name,
Data: time.Unix(item.MarketBoardListing.LastUploadTime/1000, 0).Format("2006-01-02"),
}
responseData = append(responseData, responseDataItem)
}

View File

@ -220,6 +220,7 @@ func main() {
http.HandleFunc("/price-update", singlePriceUpdateHandler)
http.HandleFunc("/status", statusHandler)
http.HandleFunc("/items-list", itemsListHandler)
http.HandleFunc("/bugged-metric-items-list", buggedMetricItemsListHandler)
http.HandleFunc("/stale-items-list", staleItemsListHandler)
http.HandleFunc("/search-listing-retainer", searchListingRetainerHandler)
http.HandleFunc("/search-listing-craftedby", searchListingCraftedbyHandler)

View File

@ -8,12 +8,12 @@
})
var itemList = []
function refreshItemTable() {
function refreshItemTable(urlPath) {
$('#itemTableBody').html("<div class='ui loading segment'>Loading items</div>")
itemList = []
let req = new XMLHttpRequest()
req.open("GET", "/stale-items-list")
req.open("GET", urlPath)
req.send()
req.onreadystatechange = function(){
if (this.readyState == 4) {
@ -41,8 +41,8 @@
tbodyString += resp[i].name
tbodyString += "</h4>"
tbodyString += "</td>"
tbodyString += "<td data-label='Last Updated'>"
tbodyString += "<p class='ui right aligned large text'>" + resp[i].lastupdated + "</p>"
tbodyString += "<td data-label='Data'>"
tbodyString += "<p class='ui right aligned large text'>" + resp[i].data + "</p>"
tbodyString += "</td>"
tbodyString += "</tr>"
}
@ -66,19 +66,24 @@
req.send()
}
refreshItemTable()
refreshItemTable("/stale-items-list")
</script>
<div class="ui segment">
<p>This page lists the most stale items part of the metric calculation. If you have XIV Launcher and are submitting data to Universalis, you can help improve accuracy of the tool by browsing these items on the market board and then waiting for the next data refresh.</p>
<b>Filter</b>
<p>
<a href="javascript:refreshItemTable('/stale-items-list')">Oldest Data (default)</a> |
<a href="javascript:refreshItemTable('/bugged-metric-items-list')">Bugged Listing Metric</a>
</p>
</div>
<table id="itemTable" class="ui compact celled striped table">
<thead>
<tr>
<th>Item Name</th>
<th>Last Updated</th>
<th>Data</th>
</tr>
</thead>
<tbody id="itemTableBody">