GitHub - typpo/asterank: asteroid database, interactive visualizations, and discovery tools
主要目的是在进行多元线性回归的时候将枚举型转换为数值型
python:
#
# The constants used in calculations for the values of asteroids.
## General constants
GENERAL_INDEX = {'cost_to_orbit': 2200, # $ / kg
}# Keys are asteroid spectra type. Values are maps from a material
# to the percent mass of each material.
SPECTRA_INDEX = {'?': {},'A': {},'B': {'hydrogen': 0.235,'nitrogen': 0.001,'ammonia': 0.001,'iron': 10,},'C': {# from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf'water': .2,'iron': .166,'nickel': .014,'cobalt': .002,# volatiles'hydrogen': 0.235,'nitrogen': 0.001,'ammonia': 0.001,},'Ch': {# from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf'water': .2,'iron': .166,'nickel': .014,'cobalt': .002,# volatiles'hydrogen': 0.235,'nitrogen': 0.001,'ammonia': 0.001,},'Cg': {# from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf'water': .2,'iron': .166,'nickel': .014,'cobalt': .002,# volatiles'hydrogen': 0.235,'nitrogen': 0.001,'ammonia': 0.001,},'Cgh': {# from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf'water': .2,'iron': .166,'nickel': .014,'cobalt': .002,# volatiles'hydrogen': 0.235,'nitrogen': 0.001,'ammonia': 0.001,},'C type': {# from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf'water': .2,'iron': .166,'nickel': .014,'cobalt': .002,# volatiles'hydrogen': 0.235,'nitrogen': 0.001,'ammonia': 0.001,},'Cb': { # transition object between C and B# from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf'water': .1,'iron': .083,'nickel': .007,'cobalt': .001,# volatiles'hydrogen': 0.235,'nitrogen': 0.001,'ammonia': 0.001,},'D': {'water': 0.000023,},'E': {},'K': { # cross between S and C# from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf'water': .1,'iron': .083,'nickel': .007,'cobalt': .001,# volatiles'hydrogen': 0.235,'nitrogen': 0.001,'ammonia': 0.001,},'L': {'magnesium silicate': 1e-30,'iron silicate': 0,'aluminum': 7},'Ld': { # copied from S'magnesium silicate': 1e-30,'iron silicate': 0,},'M': {'iron': 88,'nickel': 10,'cobalt': 0.5,},'O': {'nickel-iron': 2.965,'platinum': 1.25,},'P': { # correspond to CI, CM carbonaceous chondrites'water': 12.5,},'R': {'magnesium silicate': 1e-30,'iron silicate': 0,},'S': {'magnesium silicate': 1e-30,'iron silicate': 0,},# Sa, Sq, Sr, Sk, and Sl all transition objects (assume half/half)'Sa': {'magnesium silicate': 5e-31,'iron silicate': 0,},'Sq': {'magnesium silicate': 1e-30,'iron silicate': 0,},'Sr': {'magnesium silicate': 1e-30,'iron silicate': 0,},'Sk': {'magnesium silicate': 1e-30,'iron silicate': 0,},'Sl': {'magnesium silicate': 1e-30,'iron silicate': 0,},'S(IV)': {'magnesium silicate': 1e-30,'iron silicate': 0,},'Q': {'nickel-iron': 13.315,},'R': {'magnesium silicate': 1e-30,'iron silicate': 0,},'T': {'iron': 6,},'U': {},'V': {'magnesium silicate': 1e-30,'iron silicate': 0,},# TODO use density to decide what kind of X the object is?'X': { # TODO these vals only apply to M-type within X'iron': 88,'nickel': 10,'cobalt': 0.5,},'Xe': { # TODO these vals only apply to M-type within X'iron': 88,'nickel': 10,'cobalt': 0.5,},'Xc': { # TODO these vals only apply to M-type within X'iron': 88,'nickel': 10,'cobalt': 0.5,'platinum': 0.005,},'Xk': { # TODO these vals only apply to M-type within X'iron': 88,'nickel': 10,'cobalt': 0.5,},'comet': {# no estimates for now, because assumed mass, etc. would be off},
}# Keys are raw materials. Values are maps containing information on
# the value of these materials.
MATERIALS_INDEX = {'water': {'$_per_kg': 0.01},'hydrogen': {'$_per_kg': 3.65808137,},'nitrogen': {'$_per_kg': 0.074094,},'ammonia': {'$_per_kg': 0.01,},'oxygen': {'$_per_kg': 0.21,},'iron': {'$_per_kg': 2e-7,},'nickel': {'$_per_kg': 0.00002,},'nickel-iron': { # value unclear. averaged.'$_per_kg': 1.01e-5,},'cobalt': {'$_per_kg': 0.20,},'stainless steel': {'$_per_kg': 0.20},'platinum': {'$_per_kg': 2},'magnesium silicate': {'$_per_kg': 1e-25,},'iron silicate': {'$_per_kg': 0,},'aluminum': {'$_per_kg': 0.05}
}def valuePerKg(type):mat_price_per_kg = 0for mat, pct in SPECTRA_INDEX[type].iteritems():mat_price_per_kg += MATERIALS_INDEX[mat]['$_per_kg'] * pct / 100return mat_price_per_kgdef savedPerKg(type):# This is is a dummy calculation used to compare the cost of mining in space# to the cost of getting the same materials from earth.cto = GENERAL_INDEX['cost_to_orbit']ret = 0for mat,pct in SPECTRA_INDEX[type].iteritems():ret += cto * pct / 100return ret - (cto / 3) # assume it costs 1/3 as much to mine and get off the asteroiddef profitRatio(baseline_dv, dv):# Baseline profit is 10%, but it changes based on dvreturn baseline_dv / dv
C++代码:
#include <iostream>
#include <string>
//函数Price_p返回元素的单位价格
float Price_p(std::string str){float per_kg=0;if(str=="water")per_kg=0.01;if (str == "hydrogen")per_kg = 3.65808137;if (str == "nitrogen")per_kg = 0.074094;if (str == "ammonia")per_kg = 0.01;if (str == "oxygen")per_kg = 0.21;if (str == "iron")per_kg = 2e-7;if (str == "nickel")per_kg = 0.00002;if (str == "nickel-iron")per_kg = 1.01e-5;if (str == "ncobalt")per_kg = 0.2;if (str == "stainless steel")per_kg = 0.2;if (str == "platinum")per_kg = 2;if (str == "magnesium silicate")per_kg = 1e-25;if (str == "iron silicate")per_kg = 0;if (str == "aluminum")per_kg = 0.05;return per_kg;
}float how_Much(std::string str_00){
if(str_00=="B"){return Price_p("hydrogen")*0.235+Price_p("nitrogen")*0.001+Price_p("ammonia")*0.001+Price_p("iron")*10;}
if (str_00 == "C"){return Price_p("water") * 0.2 + Price_p("iron") * 0.166 + Price_p("nickel") * 0.014 + Price_p("cobalt") * 0.002+Price_p("hydrogen") * 0.235+ Price_p("nitrogen") * 0.001+Price_p("ammonia") * 0.001+Price_p("ammonia") *0.001;}
if (str_00== "Ch"){return Price_p("water") * 0.2 + Price_p("iron") * 0.166 + Price_p("nickel") * 0.014 + Price_p("cobalt") * 0.002+Price_p("hydrogen") * 0.235+ Price_p("nitrogen") * 0.001+Price_p("ammonia") * 0.001;}
if (str_00== "Cg"){return Price_p("water") * 0.2 + Price_p("iron") * 0.166 + Price_p("nickel") * 0.014 + Price_p("cobalt") * 0.002+Price_p("hydrogen") * 0.235+ Price_p("nitrogen") * 0.001+Price_p("ammonia") * 0.001;}
if (str_00== "Cgh"){return Price_p("water") * 0.2 + Price_p("iron") * 0.166 + Price_p("nickel") * 0.014 + Price_p("cobalt") * 0.002+Price_p("hydrogen") * 0.235+ Price_p("nitrogen") * 0.001+Price_p("ammonia") * 0.001;}
if (str_00== "C type"){return Price_p("water") * 0.2 + Price_p("iron") * 0.166 + Price_p("nickel") * 0.014 + Price_p("cobalt") * 0.002+Price_p("hydrogen") * 0.235+ Price_p("nitrogen") * 0.001+Price_p("ammonia") * 0.001;}
if (str_00 == "Cb"){return Price_p("water") * 0.1 + Price_p("iron") * 0.083 + Price_p("nickel") * 0.007 +Price_p("cobalt") * 0.001 + Price_p("hydrogen") * 0.235+ Price_p("nitrogen") * 0.001 + Price_p("ammonia") * 0.001;
}
if (str_00 == "D"){return Price_p("water") * 0.000023 ;}if (str_00 == "E"){
return 0;}if (str_00 == "K"){return Price_p("water") * 0.1 + Price_p("iron") * 0.083 + Price_p("nickel") * 0.007 +Price_p("cobalt") * 0.001 + Price_p("hydrogen") * 0.235+ Price_p("nitrogen") * 0.001 + Price_p("ammonia") * 0.001;
}
if (str_00 == "L"){return Price_p("magnesium silicate") * 1e-30 + Price_p("iron silicate") * 0 + Price_p("aluminum") * 7 ;
}
if (str_00 == "Ld"){return Price_p("magnesium silicate") * 1e-30 + Price_p("iron silicate") * 0 ;
}
if (str_00 == "M"){return Price_p("iron") * 88 + Price_p("nickel") * 10 + Price_p("cobalt") * 0.5;
}
if (str_00 == "O"){return Price_p("nickel-iron") * 2.965 + Price_p("platinum") * 1.25;
}
if (str_00 == "P"){return Price_p("water") * 12.5;
}
if (str_00 == "R"){return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "S"){return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "Sa"){return Price_p("magnesium silicate") * 5e-31+Price_p("iron silicate") * 0;
}if (str_00 == "Sq"){return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "Sr"){return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "Sk"){return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "Sl"){
return Price_p("magnesium silicate") * 1e-30 + Price_p("iron silicate") * 0;
}
if (str_00 == "S(IV)"){return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "Q"){return Price_p("nickel-iron") * 13.315;
}
if (str_00 == "R"){return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "T"){return Price_p("iron") * 6;
}
if (str_00 == "U"){return 0;
}
if (str_00 == "V"){return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "X"){return Price_p("iron") * 88+Price_p("nickel") * 10+Price_p("cobalt") * 0.5;
}
if (str_00 == "Xe"){return Price_p("iron") * 88+Price_p("nickel") * 10+Price_p("cobalt") * 0.5;
}
if (str_00 == "Xc"){return Price_p("iron") * 88+Price_p("nickel") * 10+Price_p("cobalt") * 0.5+Price_p("platinum") * 0.005;
}
if (str_00 == "Xk"){return Price_p("iron") * 88+Price_p("nickel") * 10+Price_p("cobalt") * 0.5;
}return 0;
}int main() {std::string str_00="C";while(str_00!="00") {std::cin>>str_00;std::cout<<"The price of Type "+str_00+"is:"<<how_Much(str_00);}return 0;
}
运行结果:
相当于每千克Q类型的小行星值多少美元