if not trade_relationship_exists(exporter, importer):
                continue
            print exporter + ' ' + importer
            print str(slope_data(exporter, importer)) + ' ' + str(data.export_data(2000, exporter, importer))
            f.write(str(slope_data(exporter, importer)) + ' ' + str(data.export_data(2000, exporter, importer)) + '\n')
            if importer == 'World':
                f_world.write(
                    str(slope_data(exporter, importer)) + ' ' + str(data.export_data(2000, exporter, importer)) + '\n')

        f.close()
        f_world.close()
    f_countries_list.close()
    return total_countries

data = ExportData()
data.load_file(WORLD_TRADE_FLOW_DATA_FILE_ORIGINAL, ["Value00"], should_read_world_datapoints=True)

total_countries = write_data_files_for_slope_vs_export_plots(data,'matlab', 'out/slope-vs-export-percent')
matlab_program_file = open('matlab/slope_vs_export_percent_gen.m', 'w')

matlab_program_file.write("clear" + '\n')
matlab_program_file.write("total = " + str(total_countries) + '\n')
matlab_program_file.write(
    "[country_names,all_countries,only_world]=textread('out/slope-vs-export-percent/all-countries.txt','%s %s %s' ,total)" + '\n')
matlab_program_file.write("" + '\n')
matlab_program_file.write("for i=1:total," + '\n')
matlab_program_file.write("    all_countries{i}" + '\n')
matlab_program_file.write("    all_data = load(all_countries{i})" + '\n')
matlab_program_file.write("    world_data = load(only_world{i})" + '\n')
matlab_program_file.write("" + '\n')
matlab_program_file.write("    if size(all_data)~=[0,0]" + '\n')
from project.config import WORLD_TRADE_FLOW_DATA_FILE_ORIGINAL
from project.export_data.exportdata import ExportData
from project.signed_networks.definitions import definition_C3, args_for_definition_C
from project.signed_networks.structural_balance.metrics.vertex import degree_sum, degree_count, positive_edge_count, negative_edge_count
from project.util import file_safe

data = ExportData()
data.load_file('../../' + WORLD_TRADE_FLOW_DATA_FILE_ORIGINAL, should_read_world_datapoints=True)

definition = definition_C3
def_args1 = args_for_definition_C(10, 5000)
def_args2 = args_for_definition_C(10, 1000)


def print_degree_sum_over_time(args, other_args, this, other):
    print "x=%s;" % str([year for year in data.all_years]).replace(",", " ")
    for A in data.countries():
        print "degreecount=%s;" % str([degree_count(data, year, A, definition, args) for year in data.all_years]).replace(",", " ")
        print "degreesum1=%s;" % str([degree_sum(data, year, A, definition, args) for year in data.all_years]).replace(",", " ")
        print "positivecount1=%s;" % str([positive_edge_count(data, year, A, definition, args) for year in data.all_years]).replace(",", " ")
        print "negativecount1=%s;" % str([negative_edge_count(data, year, A, definition, args) for year in data.all_years]).replace(",", " ")
        print "degreesum2=%s;" % str([degree_sum(data, year, A, definition, other_args) for year in data.all_years]).replace(",", " ")
        print "plot(x,degreesum1,'b-o',x,degreesum2,'b-*',x,degreecount,'m-o',x,positivecount1,'g-o',x,negativecount1,'r-o');"
        print "hline = refline([0 0]);"
        print "set(hline,'Color','b');"
        print "legend('degree-sum1(T2=%d)','degree-sum2(T2=%d)','degree-count','positivecount1','negativecount1','Location','Best')" %(this,other)
        print "saveas(gcf,'%s-%d','png');" % (file_safe(A),this)


print_degree_sum_over_time(def_args1, def_args2, 5000, 1000)
print_degree_sum_over_time(def_args2, def_args1, 1000, 5000)
예제 #3
0
from project.config import  WORLD_TRADE_FLOW_DATA_FILE_ORIGINAL
from project.export_data import strongties
from project.export_data.exportdata import ExportData
from project.export_data.strongties import is_there_a_strong_tie_method_B, strong_tie_def_args
from project.traids_vs_degree_plot import config
from project.traids_vs_degree_plot.csv_writer.csv_writer import csv_write


def write_out_graph_data_for_traids_vs_degree_plot(data):
    for year in data.all_years:
        matrix_for_a_year = strongties.get_relationship_matrix(data, year, is_there_a_strong_tie_method_B,
            strong_tie_def_args(config.STRONG_TIES_LOWER_BOUND, config.STRONG_TIES_UPPER_BOUND))
        csv_write(config.graph_data_file_name(year), strongties.graph_data(matrix_for_a_year))

data = ExportData()
data.load_file(WORLD_TRADE_FLOW_DATA_FILE_ORIGINAL)
write_out_graph_data_for_traids_vs_degree_plot(data)