Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 54 additions & 62 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,67 +246,6 @@ export async function fetchProcessData(processName, periods, currentHeight) {
}
}



/**
* Fetches transaction counts for a specific process type over multiple time periods
* @param {string} processName - The name of the process
* @param {Array} periods - Array of time periods with start/end heights
* @returns {Promise<Array>} Array of transaction counts for each period
*/
export async function fetchVolumeData() {
try {
// Create a unique cache key for this request
const cacheKey = `volume-stats`;

// Check if we have cached data that's less than 30min old
if (responseCache.has(cacheKey)) {
const { data, timestamp } = responseCache.get(cacheKey);
if (Date.now() - timestamp < 30 * 60 * 1000) {
return data;
}
}

const response = await fetch ('https://raw.githubusercontent.com/Jonny-Ringo/the_eye_of_AO/main/data/volume-stats.json');
if (!response.ok) {
throw new Error(`Network error: ${response.status} ${response.statusText}`);

}
// Cache the result
const rawData = await response.json();

const volumeData = rawData.volumeData;

// Transform the data into the required format
const processedData = {
AO: volumeData.AO.map(entry => ({
timestamp: new Date(entry.date).getTime(),
value: entry.volume
})),
wAR: volumeData.wAR.map(entry => ({
timestamp: new Date(entry.date).getTime(),
value: entry.volume
})),
wUSDC: volumeData.wUSDC.map(entry => ({
timestamp: new Date(entry.date).getTime(),
value: entry.volume
}))
};

responseCache.set(cacheKey, {
data: processedData,
timestamp: Date.now()
});
console.log('Processed volume data:', processedData);
return processedData;
} catch (error) {
console.error("Error fetching volume data:", error);
throw error;
}
}



/**
* Fetches daily player stats for Stargrid Battle Tactics
* @returns {Promise<Array>} Array of daily player count data
Expand Down Expand Up @@ -361,10 +300,63 @@ export async function fetchStargridStats() {
}
}

/**
* Fetches Rune Realm Streaks data
* @returns {Promise<Object>} Object with streak breakdown data by day
*/
export async function fetchRuneRealmStats() {
try {
const cacheKey = 'rune-realm-streaks';
// Use cached data if it's less than 15 minutes old
if (responseCache.has(cacheKey)) {
const { data, timestamp } = responseCache.get(cacheKey);
if (Date.now() - timestamp < 15 * 60 * 1000) {
return data;
}
}

const response = await dryrun({
process: 'GhNl98tr7ZQxIJHx4YcVdGh7WkT9dD7X4kmQOipvePQ',
data: '',
tags: [
{ name: "Action", value: "GetCheckinMapping" },
{ name: "Data-Protocol", value: "ao" },
{ name: "Type", value: "Message" },
{ name: "Variant", value: "ao.TN.1" }
],
});

if (!response || !response.Messages || !response.Messages[0]) {
throw new Error('Invalid response from Rune Realm process');
}

// Get the first message's data
const message = response.Messages[0];
const messageData = JSON.parse(message.Data);

// Extract the History object from the data
if (!messageData || !messageData.History) {
throw new Error('No History data found in response');
}

const historyData = messageData.History;

// Cache the result
responseCache.set(cacheKey, {
data: historyData,
timestamp: Date.now()
});

return historyData;
} catch (error) {
console.error("Error fetching Rune Realm stats:", error);
throw error;
}
}

/**
* Clears the API response cache
*/
export function clearCache() {
responseCache.clear();
}
}
Loading