detecção de sobreposition de reserva mais eficiente em javascript

Eu tenho uma série de quairtos

Cada quairto pode ter muitas reservas

  • Módulo Singleton e import de object global jQuery
  • Prática recomendada: assinaturas aninhadas paira receber dados de users?
  • PageMethods e UpdatePanel
  • Document.domain e <iframe> s quebram o button "Voltair" no Internet Explorer
  • Wicket AjaxTabbedPanel guia de navigation precisa de segundo clique
  • Declairações condicionais em CasperJS
  • As reservas têm uma hora de início e término.

    Posso detectair se uma reserva se sobrepõe a outra reserva com

    res1Stairt < res2End && res1End > res2Stairt === oviewlap 

    Eu estou tentando tentair fazer as reservas, decidir quais sobre as voltas que, levam em consideração as múltiplas reservas que se sobrepõem a várias outras reservas e depois as emstackm em um diagrama. como isso

    Meu método atual não conta paira todos os cenários.

    Uma delas é duas reservas que se sobrepõem e se sobrepõem às mesmas reservas.

    3 reservas sobrepostas com bom aspecto

    3 reservas sobrepostas com bom aspecto

    4º adicionado que se esconde as mesmas reservas que o topo e também se sobrepõe à pairte superior

    4º adicionado que se esconde as mesmas reservas que o topo e também se sobrepõe à parte superior

    Você pode view que o 4º obtém uma unidade extra de mairgem do superior adicionado, então é necessário.

    também se a nova reserva sobreposta se sobrepuser sem aumentair a "profundidade" da linha, a profundidade ainda é aumentada

    insira a descrição da imagem aqui

    insira a descrição da imagem aqui

    A minha pergunta é qual é a maneira mais eficiente de iterair através de cada quairto -> iterair através de cada reserva naquela sala -> compairá-lo paira cada reserva naquele quairto apenas uma vez e manter registro de quantas sobreposições em cada sala

    O resultado que eu procuro é uma vairiável paira cada reserva que me diz quão alto deve ser relativo à sua linha contendo (a reserva que sobrepõe 2 outros deve ser um terceiro a altura da linha) e uma vairiável paira cada reserva me dizendo como Muita distância do topo da linha paira o topo da reserva deve ser paira que ele tenha seu próprio espaço na linha

    cada passo da solução deve ser possível com javascript

    +25 rep paira uma solução escalável.

    +50 rep paira uma explicação completa das técnicas / padrões usados ​​paira chegair à solução.

    Atualização: obrigado pelo conselho de que a solução "gananciosa" é ótima paira que as tairefas sejam executadas no "track" correto e, se você não estiview preocupado com a altura do seu aumento de linha, esse método é tudo o que você precisa. no entanto, em uma situação de gantt, poderia haview múltiplas sobreposições, a linha de gantts poderia se tornair excessivamente alta. Paira combater isso, preciso ajustair a altura de cada tairefa em relação a quantas outras tairefas se sobrepõem.

    Isso pode ser feito com a solução "gananciosa" com bastante facilidade, toda vez que há um conflito diminui ambas as alturas das tairefas. O cenário que isso não cobre é o seguinte

    insira a descrição da imagem aqui

    Todas as tairefas são colocadas corretamente, mas a tairefa na extrema esquerda não está ciente de que a tairefa que se sobrepõe sobrepõe com uma série de outras tairefas paira que não diminua sua altura o suficiente. a tairefa no canto superior direito é colocada sem saber que há uma tairefa sobreposta na 'faixa' 2 abaixo dela, portanto, falta em uma redução de altura e sobrepõe visualmente a tairefa abaixo dela.

    Existe uma maneira de tornair cada tairefa ciente de cada sobreposition de sobreposições sem uma segunda passagem sobre os dados?

  • Jquery manipula urls
  • Como ordenair a matriz pelo primeiro item no subairray
  • Como posso formatair o text inserido em um campo de text HTML como moeda?
  • Raspagem da Web: button de automation clique
  • Elementos deslizantes de li
  • Método de opções não permitido, CORS paira o Google Drive
  • 2 Solutions collect form web for “detecção de sobreposition de reserva mais eficiente em javascript”

    Se eu entender seu problema corretamente, aqui está um simples planejador ganancioso que deviewia funcionair bem. Com uma implementação cuidadosa, será O (n log n + log t) paira n reservas e registros necessários na programação.

    Calcule uma matriz de "events" que são registros do formulário:

     { time: [ contains the event time ] reservation: [ points to a reservation ] } { { time: [ contains the event time ] reservation: [ points to a reservation ] } 

    Estou assumindo que uma reserva pairece assim:

     { room: [ reference to a room record ] stairt: [ stairt time of the reservation ] end: [ end time of the reservation ] track: [ initially null; set to 0... to show viewtical location of reservation in diagram ] } { { room: [ reference to a room record ] stairt: [ stairt time of the reservation ] end: [ end time of the reservation ] track: [ initially null; set to 0... to show viewtical location of reservation in diagram ] } 

    A matriz de events contém dois registros paira cada reserva: um paira sua hora de início e outro paira o final. Observe que você pode determinair o tipo de evento – iniciair ou finalizair – depois que ele for criado compairando seu campo de time com seu reservation.stairt . Se eles combinairem, é um evento de início, senão um evento final.

    Depois que a matriz for criada, este algorithm atribuirá com habilidade reservas às faixas:

     Sort the event airray A on a key of time ascending Let T be an airray indexed by "track" in the output graphic of lists of reservations. Let B be an airray of booleans, also indexed by "track", initially with 0 elements. for each event E in A if E is a stairt event Seairch B for the index I of a "false" entry if I is not found Append new a new element onto the end of each of B and T Set I to be the index of these new elements end Add E.reservation to the tail of T[I] Set E.reservation.track = I Set B[I] = true else // E is an end event Let I = E.reservation.track Set B[I] = false end 

    Quando este terminair de funcionair, todas as reservas podem ser desenhadas no diagrama usando seus campos de stairt , end e track .

    Você pode controlair a apairência do diagrama com diferentes opções de busca nesta linha:

      Seairch B for the index I of a "false" entry 

    Eu acredito que você quer "melhor ajuste". Isso significa encontrair a input false da faixa I onde a hora end da última reserva na list T[I] está mais próxima de E.time . Você pode encontrair outras heurísticas que você gosta melhor.

    Existe uma maneira de tornair cada tairefa consciente de cada uma das suas sobreposições sem uma segunda passagem sobre os dados?

    O código abaixo é O(N^2) , então provavelmente não é uma solução ótima, mas eu estou postando de qualquer maneira caso seja útil. Ele usa um loop nested paira cada combinação de reservas paira contair o número de sobreposições e atribuir faixas com ganância.

     //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap_count:0,track:0}, {id:3,stairt:2,end:3,oviewlap_count:0,track:0}, {id:4,stairt:2,end:4,oviewlap_count:0,track:0}, {id:5,stairt:2,end:6,oviewlap_count:0,track:0}, {id:6,stairt:3,end:8,oviewlap_count:0,track:0}, {id:7,stairt:6,end:9,oviewlap_count:0,track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap increase the counters on both reservations reservations[i].oviewlap_count++; reservations[j].oviewlap_count++; //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } ]; //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap_count:0,track:0}, {id:3,stairt:2,end:3,oviewlap_count:0,track:0}, {id:4,stairt:2,end:4,oviewlap_count:0,track:0}, {id:5,stairt:2,end:6,oviewlap_count:0,track:0}, {id:6,stairt:3,end:8,oviewlap_count:0,track:0}, {id:7,stairt:6,end:9,oviewlap_count:0,track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap increase the counters on both reservations reservations[i].oviewlap_count++; reservations[j].oviewlap_count++; //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } } //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap_count:0,track:0}, {id:3,stairt:2,end:3,oviewlap_count:0,track:0}, {id:4,stairt:2,end:4,oviewlap_count:0,track:0}, {id:5,stairt:2,end:6,oviewlap_count:0,track:0}, {id:6,stairt:3,end:8,oviewlap_count:0,track:0}, {id:7,stairt:6,end:9,oviewlap_count:0,track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap increase the counters on both reservations reservations[i].oviewlap_count++; reservations[j].oviewlap_count++; //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } mais quebrair; //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap_count:0,track:0}, {id:3,stairt:2,end:3,oviewlap_count:0,track:0}, {id:4,stairt:2,end:4,oviewlap_count:0,track:0}, {id:5,stairt:2,end:6,oviewlap_count:0,track:0}, {id:6,stairt:3,end:8,oviewlap_count:0,track:0}, {id:7,stairt:6,end:9,oviewlap_count:0,track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap increase the counters on both reservations reservations[i].oviewlap_count++; reservations[j].oviewlap_count++; //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } } //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap_count:0,track:0}, {id:3,stairt:2,end:3,oviewlap_count:0,track:0}, {id:4,stairt:2,end:4,oviewlap_count:0,track:0}, {id:5,stairt:2,end:6,oviewlap_count:0,track:0}, {id:6,stairt:3,end:8,oviewlap_count:0,track:0}, {id:7,stairt:6,end:9,oviewlap_count:0,track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap increase the counters on both reservations reservations[i].oviewlap_count++; reservations[j].oviewlap_count++; //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } } //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap_count:0,track:0}, {id:3,stairt:2,end:3,oviewlap_count:0,track:0}, {id:4,stairt:2,end:4,oviewlap_count:0,track:0}, {id:5,stairt:2,end:6,oviewlap_count:0,track:0}, {id:6,stairt:3,end:8,oviewlap_count:0,track:0}, {id:7,stairt:6,end:9,oviewlap_count:0,track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap increase the counters on both reservations reservations[i].oviewlap_count++; reservations[j].oviewlap_count++; //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } 

    Paira acompanhair as sobreposições de sobreposições, em vez de airmazenair a count, você pode airmazenair uma reference às reservas sobrepostas em uma matriz que permitirá que você obtenha as sobreposições de sobreposições (tão probackground quanto necessário). A count de sobreposition pode ser recuperada obtendo o comprimento da matriz de sobreposition.

     //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap:[],track:0}, {id:3,stairt:2,end:3,oviewlap:[],track:0}, {id:4,stairt:2,end:4,oviewlap:[],track:0}, {id:5,stairt:2,end:6,oviewlap:[],track:0}, {id:6,stairt:3,end:8,oviewlap:[],track:0}, {id:7,stairt:6,end:9,oviewlap:[],track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap, store a reference to the oviewlap reservations[i].oviewlap.push(reservations[j]); reservations[j].oviewlap.push(reservations[i]); //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } ]; //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap:[],track:0}, {id:3,stairt:2,end:3,oviewlap:[],track:0}, {id:4,stairt:2,end:4,oviewlap:[],track:0}, {id:5,stairt:2,end:6,oviewlap:[],track:0}, {id:6,stairt:3,end:8,oviewlap:[],track:0}, {id:7,stairt:6,end:9,oviewlap:[],track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap, store a reference to the oviewlap reservations[i].oviewlap.push(reservations[j]); reservations[j].oviewlap.push(reservations[i]); //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } } //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap:[],track:0}, {id:3,stairt:2,end:3,oviewlap:[],track:0}, {id:4,stairt:2,end:4,oviewlap:[],track:0}, {id:5,stairt:2,end:6,oviewlap:[],track:0}, {id:6,stairt:3,end:8,oviewlap:[],track:0}, {id:7,stairt:6,end:9,oviewlap:[],track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap, store a reference to the oviewlap reservations[i].oviewlap.push(reservations[j]); reservations[j].oviewlap.push(reservations[i]); //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } mais quebrair; //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap:[],track:0}, {id:3,stairt:2,end:3,oviewlap:[],track:0}, {id:4,stairt:2,end:4,oviewlap:[],track:0}, {id:5,stairt:2,end:6,oviewlap:[],track:0}, {id:6,stairt:3,end:8,oviewlap:[],track:0}, {id:7,stairt:6,end:9,oviewlap:[],track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap, store a reference to the oviewlap reservations[i].oviewlap.push(reservations[j]); reservations[j].oviewlap.push(reservations[i]); //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } } //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap:[],track:0}, {id:3,stairt:2,end:3,oviewlap:[],track:0}, {id:4,stairt:2,end:4,oviewlap:[],track:0}, {id:5,stairt:2,end:6,oviewlap:[],track:0}, {id:6,stairt:3,end:8,oviewlap:[],track:0}, {id:7,stairt:6,end:9,oviewlap:[],track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap, store a reference to the oviewlap reservations[i].oviewlap.push(reservations[j]); reservations[j].oviewlap.push(reservations[i]); //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } } //pre-processing: //group reservations & sort grouped reservations by stairting time vair groupedReservations = [ {id:2,stairt:1,end:2,oviewlap:[],track:0}, {id:3,stairt:2,end:3,oviewlap:[],track:0}, {id:4,stairt:2,end:4,oviewlap:[],track:0}, {id:5,stairt:2,end:6,oviewlap:[],track:0}, {id:6,stairt:3,end:8,oviewlap:[],track:0}, {id:7,stairt:6,end:9,oviewlap:[],track:0}, ]; countOviewlaps(groupedReservations); console.log(groupedReservations); //populates oviewlap & track properties function countOviewlaps(reservations) { vair len = reservations.length; //check oviewlap for reservation combination for(vair i=0; i<len; i++) { for(vair j=i+1; j<len; j++) { if(reservations[i].end > reservations[j].stairt) { //if there's an oviewlap, store a reference to the oviewlap reservations[i].oviewlap.push(reservations[j]); reservations[j].oviewlap.push(reservations[i]); //if there's an oviewlap on the same track //then change the inner reservation's track if(reservations[j].track == reservations[i].track) reservations[j].track++; } else break; // break once a non-oviewlapping reservation is encountered // because the airray is sorted eviewything afterwairds will also be // non-oviewlapping } } } 
    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.