ruby - Best way to implement a large 2D Lookup Table in Rails -


i developing rails app , 1 of actions compares 2 of same kind of objects , returns decimal value between 0 , 1. there 800 objects need compared, there 800*800 possible decimal values can returned. each action call requires 300 or comparisons, made via api.

because of number of api calls needed, have decided best approach make lookup table 800*800 api comparison values stored locally, avoid having rely on api, has call limits , significant overhead per call.

basically have decided lookup table best suits task (although open suggestions on too).

my question this: best way implement 2 dimensional lookup table ~800 "rows" , ~800 "columns" in rails? example, if wanted compare objects 754 , 348, best create models rows , columns , access decimal comparison like:

object1.754.object2.348 # => 0.8738 

or should store of values in csv or this? if better approach, how should approach setting up? relatively new rails world apologies if obvious answer dangling in front of me!

bear in mind entire point of approach avoid overheads api calls , avoid large waiting times end user, looking time-efficient way approach task!

i consider hash of hashes, retrieve values with:

my_hash[754][348] => 0.8738 

if might not have loaded value particular combination you'd want careful use:

my_hash[754].try(:[],348) 

there subtleties in implimentation loading hash make beneficial use hashie gem.

https://rubygems.org/gems/hashie/versions/3.4.2

if wanted persist values can written database using serialize, , can extend method provide expiry dates on values if wished.


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -