diff --git a/app/src/main/java/eu/m724/vastapp/vastai/Utils.kt b/app/src/main/java/eu/m724/vastapp/vastai/Utils.kt new file mode 100644 index 0000000..3ca177a --- /dev/null +++ b/app/src/main/java/eu/m724/vastapp/vastai/Utils.kt @@ -0,0 +1,17 @@ +package eu.m724.vastapp.vastai + +class Utils { + companion object { + fun mbToMib(mb: Number): Double { + return mb.toDouble() * 1.048576 + } + + fun gbToGib(gb: Number): Double { + return gb.toDouble() * 1.073741824 + } + + fun mibToMb(mib: Number): Double { + return mib.toDouble() / 1.073741824 + } + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/m724/vastapp/vastai/data/Instance.kt b/app/src/main/java/eu/m724/vastapp/vastai/data/Instance.kt new file mode 100644 index 0000000..64347f7 --- /dev/null +++ b/app/src/main/java/eu/m724/vastapp/vastai/data/Instance.kt @@ -0,0 +1,70 @@ +package eu.m724.vastapp.vastai.data + +import eu.m724.vastapp.vastai.Utils +import org.json.JSONObject + +/** + * represents an instance, rented or not + * units are in decimal bytes that is 1000 MB GB + */ +data class Instance( + val id: Int, + val machine: Machine, + + /** memory available in instance in MB */ + val instanceMemoryMb: Int, + /** cpu cores available in instance like 6.1 */ + val instanceCpuCores: Double, + /** how many (same) gpus the instance has*/ + val instanceNumGpus: Int, + /** "Deep Learning Performance", it's very specific like 15.679831880208411 */ + val dlPerf: Double, + + /** dollars per hour excluding storage costs, like 0.32 */ + val dphBase: Double, + /** storage cost 1 GB / 30 days (720 hours) + * to get hourly, divide it by 720 and multiply by GBs */ + val storageCostGbMo: Double, + /** dollars per 1 GB of download (on site it shows TB as 1024) **/ + val inetDownCostGb: Double, + /** dollars per 1 GB of upload (on site it shows TB as 1024) **/ + val inetUpCostGb: Double, + + /** if you're bidding this instance, always false in marketplace (or not?) */ + val isBid: Boolean, + /** the minimum bid you can make, as dph + * website shows more I don't know why */ + val minBid: Double, + + /** since when the instance is available for rental in unix seconds + * if rented by you, it's since when the machine is rented + * at least I think because it's recent and unavailable machines don't have that */ + val startDate: Long, + /** when instance will expire as unix seconds, like 1861891577 */ + val endDate: Long, + + /** is the instance available for rental */ + val available: Boolean +) { + companion object { + fun fromJson(json: JSONObject): Instance { + return Instance( + json.getInt("id"), + Machine.fromJson(json), + json.getInt("cpu_ram"), + json.getDouble("cpu_cores_effective"), + json.getInt("num_gpus"), + json.getDouble("dlperf"), + json.getDouble("dph_base"), + json.getDouble("storage_cost"), + json.getDouble("inet_down_cost"), + json.getDouble("inet_up_cost"), + json.getBoolean("is_bid"), + json.getDouble("min_bid"), + json.getDouble("start_date").toLong(), + json.getLong("end_date"), + json.getBoolean("rentable") + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/m724/vastapp/vastai/data/Machine.kt b/app/src/main/java/eu/m724/vastapp/vastai/data/Machine.kt new file mode 100644 index 0000000..b5ed702 --- /dev/null +++ b/app/src/main/java/eu/m724/vastapp/vastai/data/Machine.kt @@ -0,0 +1,123 @@ +package eu.m724.vastapp.vastai.data + +import eu.m724.vastapp.vastai.Utils +import org.json.JSONObject +import javax.crypto.Mac + +/** + * represents a machine + * that is the machine with physical resources + */ +data class Machine( + val id: Int, + /** machine host's id, that is the account the machine is listed by */ + val hostId: Int, + + /** motherboard name, like X99 or TUF GAMING X570 */ + val motherboardName: String, + /** machine ram in MB */ + val memory: Double, + + /** cpu architecture, like amd64 */ + val cpuArch: String, + /** machine cpu cores like 12 */ + val cpuCores: Int, + /** readable cpu name like xeon something */ + val cpuName: String, + + /** disk bandwidth in MB/s (TODO find out) like 1225.1 */ + val diskBandwidth: Double, + /** disk name, like nvme (literally) or a model like SPCC M.2 PCIe SSD */ + val diskName: String, + /** available disk space on host in GB (TODO find out) like 95.833336 */ + val diskSpace: Double, + + /** pcie gpu lanes like 8 */ + val gpuLanes: Int, + /** vram bandwidth in GB/s (TODO find out) like 3518 */ + val gpuMemoryBandwidth: Double, + /** gpu name like RTX 4090 */ + val gpuName: String, + /** vram in MB */ + val gpuMemoryMb: Int, + + /** max cuda version like 12.2 */ + val cudaMaxGood: Double, + /** nvidia driver version like 545.23.06 */ + val driverVersion: String, + /** not sure, changes with gpu series, like 860 for rtx 3000 series*/ + val computeCap: Int, + + /** pcie version like 3.0 or 4.0 */ + val pcieGen: Double, + /** pcie bandwidth in GB/s (TODO find out) like 11.7 */ + val pcieBandwidth: Double, + + /** download speed in Mbps */ + val inetDownSpeedMbps: Double, + /** upload speed in Mbps */ + val inetUpSpeedMbps: Double, + /** amount of open ports like 99 */ + val directPortCount: Int, + /** public ip address of the machine, like 192.0.2.1 */ + val publicAddress: String, + /** self explanatory but not sure if matters */ + val isStaticAddress: Boolean, + /** formatted as City, CC like Quebec, CA */ + val geolocation: String, + + /** reliability of the machine 0-1 */ + val reliability: Double, + /** how is the machine hosted, 0 normal, 1 datacenter */ + val hostingType: Int, + val verification: MachineVerification +) { + companion object { + fun fromJson(json: JSONObject): Machine { + return Machine( + json.getInt("machine_id"), + json.getInt("host_id"), + json.getString("mobo_name"), + json.getInt("cpu_ram") / json.getDouble("gpu_frac"), + json.getString("cpu_arch"), + json.getInt("cpu_cores"), + json.getString("cpu_name"), + json.getDouble("disk_bw"), + json.getString("disk_name"), + json.getDouble("disk_space"), + json.getInt("gpu_lanes"), + json.getDouble("gpu_mem_bw"), + json.getString("gpu_name"), + Utils.mibToMb(json.getInt("gpu_ram")).toInt(), + json.getDouble("cuda_max_good"), + json.getString("driver_version"), + json.getInt("compute_cap"), + json.getDouble("pci_gen"), + json.getDouble("pcie_bw"), + json.getDouble("inet_down"), + json.getDouble("inet_up"), + json.getInt("direct_port_count"), + json.getString("public_ipaddr"), + json.getBoolean("static_ip"), + json.getString("geolocation"), + json.getDouble("reliability2"), + json.getInt("hostingType"), + MachineVerification.fromString(json.getString("verification")) + ) + } + } +} + +enum class MachineVerification { + VERIFIED, UNVERIFIED, VERIFICATION_REMOVED; + + companion object { + fun fromString(text: String): MachineVerification { + return when (text) { + "verified" -> VERIFIED + "deverified" -> VERIFICATION_REMOVED + else -> UNVERIFIED + } + } + } +} \ No newline at end of file