Exemple #1
1
/*******************

Eens hij aan het algoritme begonnen is, gaat hij het blijven volhouden tot hij klaar is met laden tenzij de state aangepast wordt. 

*******************/
int charge_NiMH(int socLoad){
	int V_bat;
	int sleepTime,sleepTime_fin;
	
	init_V_max();
	setCurrentCharger(C);
	// Slaaptijd tussen opeenvolgende metingen, in milliseconden
	sleepTime = 100;
	sleepTime_fin =5000;

	while (getLoadFactor()>0) {
		setLEDS(getLoadFactor());
		if (isAtChargeLimit(socLoad)) return 2;
		V_bat=getVoltage();
	
		if(V_max<V_bat){
			V_max=V_bat;
		}
	
		if(V_bat<V_max*0.9975){
			//hoe kan je controleren of dit 5 sec lang zo blijft (andere tijdsduur is ook goed, maar men stelt 5 sec voor)
			usleep(sleepTime_fin*1000);
			if(V_bat<V_max*0.9975){
				return 1;
			}
		}

		usleep(sleepTime*1000);
	}
	return 0;
}
Exemple #2
0
/*********************

Hier gaan we de batterij ontladen.

**********************/
void dischargeAlgorthm(){
	while(getLoadFactor() < 0 && getStateOfCharge() > (specs.volt_max_cell*specs.nr_of_cells)*MINMARGE){
		setLEDS(-1*getLoadFactor());

		// Stel de stroom in op 1 x C
		current = 1*specs.capacity;
		setCurrentCharger(-1*getLoadFactor());
		usleep(3000000);//we slapen drie seconden
	}
}
Exemple #3
0
//prints the efficiency data of the hash table
void hashADT::printEfficiency(ostream & os)
{
	os << "Efficiency Data: " << endl;
	os << "Load Factor: " << getLoadFactor() << endl;
	os << "Longest Linked List: " << getLongestLink() << endl;
	os << "Average Number of Nodes in Linked Lists: " << getAvgNode() << endl;
}
Exemple #4
0
BlockInputStreams StorageSystemDictionaries::read(
    const Names & column_names,
    const ASTPtr & query,
    const Context & context,
    QueryProcessingStage::Enum & processed_stage,
    const size_t max_block_size,
    const unsigned)
{
    check(column_names);
    processed_stage = QueryProcessingStage::FetchColumns;

    ColumnWithTypeAndName col_name{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "name"};
    ColumnWithTypeAndName col_origin{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "origin"};
    ColumnWithTypeAndName col_type{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "type"};
    ColumnWithTypeAndName col_key{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "key"};
    ColumnWithTypeAndName col_attribute_names{
        std::make_shared<ColumnArray>(std::make_shared<ColumnString>()),
        std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()),
        "attribute.names"
    };
    ColumnWithTypeAndName col_attribute_types{
        std::make_shared<ColumnArray>(std::make_shared<ColumnString>()),
        std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()),
        "attribute.types"
    };
    ColumnWithTypeAndName col_has_hierarchy{std::make_shared<ColumnUInt8>(), std::make_shared<DataTypeUInt8>(), "has_hierarchy"};
    ColumnWithTypeAndName col_bytes_allocated{std::make_shared<ColumnUInt64>(), std::make_shared<DataTypeUInt64>(), "bytes_allocated"};
    ColumnWithTypeAndName col_query_count{std::make_shared<ColumnUInt64>(), std::make_shared<DataTypeUInt64>(), "query_count"};
    ColumnWithTypeAndName col_hit_rate{std::make_shared<ColumnFloat64>(), std::make_shared<DataTypeFloat64>(), "hit_rate"};
    ColumnWithTypeAndName col_element_count{std::make_shared<ColumnUInt64>(), std::make_shared<DataTypeUInt64>(), "element_count"};
    ColumnWithTypeAndName col_load_factor{std::make_shared<ColumnFloat64>(), std::make_shared<DataTypeFloat64>(), "load_factor"};
    ColumnWithTypeAndName col_creation_time{std::make_shared<ColumnUInt32>(), std::make_shared<DataTypeDateTime>(), "creation_time"};
    ColumnWithTypeAndName col_last_exception{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "last_exception"};
    ColumnWithTypeAndName col_source{std::make_shared<ColumnString>(), std::make_shared<DataTypeString>(), "source"};

    const auto & external_dictionaries = context.getExternalDictionaries();
    const std::lock_guard<std::mutex> lock{external_dictionaries.dictionaries_mutex};

    for (const auto & dict_info : external_dictionaries.dictionaries)
    {
        col_name.column->insert(dict_info.first);
        col_origin.column->insert(dict_info.second.origin);

        if (dict_info.second.dict)
        {
            const auto dict_ptr = dict_info.second.dict->get();

            col_type.column->insert(dict_ptr->getTypeName());

            const auto & dict_struct = dict_ptr->getStructure();
            col_key.column->insert(dict_struct.getKeyDescription());

            col_attribute_names.column->insert(ext::map<Array>(dict_struct.attributes, [] (auto & attr) -> decltype(auto) {
                return attr.name;
            }));
            col_attribute_types.column->insert(ext::map<Array>(dict_struct.attributes, [] (auto & attr) -> decltype(auto) {
                return attr.type->getName();
            }));
            col_bytes_allocated.column->insert(dict_ptr->getBytesAllocated());
            col_query_count.column->insert(dict_ptr->getQueryCount());
            col_hit_rate.column->insert(dict_ptr->getHitRate());
            col_element_count.column->insert(dict_ptr->getElementCount());
            col_load_factor.column->insert(dict_ptr->getLoadFactor());
            col_creation_time.column->insert(std::chrono::system_clock::to_time_t(dict_ptr->getCreationTime()));
            col_source.column->insert(dict_ptr->getSource()->toString());
        }
        else
        {
            col_type.column->insertDefault();
            col_key.column->insertDefault();
            col_attribute_names.column->insertDefault();
            col_attribute_types.column->insertDefault();
            col_bytes_allocated.column->insertDefault();
            col_query_count.column->insertDefault();
            col_hit_rate.column->insertDefault();
            col_element_count.column->insertDefault();
            col_load_factor.column->insertDefault();
            col_creation_time.column->insertDefault();
            col_source.column->insertDefault();
        }

        if (dict_info.second.exception)
        {
            try
            {
                std::rethrow_exception(dict_info.second.exception);
            }
            catch (...)
            {
                col_last_exception.column->insert(getCurrentExceptionMessage(false));
            }
        }
        else
            col_last_exception.column->insertDefault();
    }

    Block block{
        col_name,
        col_origin,
        col_type,
        col_key,
        col_attribute_names,
        col_attribute_types,
        col_bytes_allocated,
        col_query_count,
        col_hit_rate,
        col_element_count,
        col_load_factor,
        col_creation_time,
        col_last_exception,
        col_source
    };

    return BlockInputStreams{1, std::make_shared<OneBlockInputStream>(block)};
}
Exemple #5
0
/*******************

Het oplaadalgoritme voor de lipo batterij zit hier geimplementeerd.

*******************/
int charge_LiPo(battery* spec, int socLoad){
	// Definitie van variabelen
	int k;
	int voltage;
	int current;
	int sleepTime;

	// Slaaptijd tussen opeenvolgende metingen, in milliseconden
	sleepTime = 100;

	// Initialisatie
	k = 1;


	// Eerste fase:
	// Legt een constante stroom aan zolang de spanning onder de V_treshold blijft.
	do {	
		setLEDS(getLoadFactor());
		// Stopconditie
		if (charging == 0||load<=0) return 0;
		if (isAtChargeLimit(socLoad)) return 2;

		// Meet huidige spanning
		voltage = getVoltage();

		// Stel de stroom in op 1 x C
		current = 1*spec->capacity;
		setCurrentCharger(current);

		// Wacht enkele milliseconden vooraleer volgende meting uit te voeren.
		usleep(sleepTime*1000);
	} while (voltage < (spec->volt_max_cell*spec->nr_of_cells)*MARGE);


	// Meet nu zowel stroom als spanning
	voltage = getVoltage();
	current = getCurrent();

	// Tweede fase:
	// Laat de stroom afnemen.
	// Wacht totdat de spanning terug V_threshold is en herhaal
	// Stroom neemt per iteratie 10% af
	while (current > (1-MARGE)*spec->capacity) {

		// Stopconditie
		if (charging == 0||getLoadFactor()<=0) return 0;
		if (isAtChargeLimit(socLoad)) return 2;

		// Als spanning ongeveer V_threshold is, verlaag de stroom
		if (voltage > (spec->volt_max_cell*spec->nr_of_cells)*MARGE) k++;

		// Stel stroom in
		current = spec->capacity*(1-(k/10));
		setCurrentCharger(current);

		// Meet de nieuwe spanning
		voltage = getVoltage();

		// Wacht enkele milliseconden tot volgende meting
		usleep(sleepTime*1000);
	}

	// Opladen voltooid
	return 1; 
}